How to query documents by contents of nested array

I’m having trouble trying to figure out the N1QL syntax to query documents by contents of a nested array. For example, using the tutorial document format, how to I find the first names of all children aged 17. I want something like the results of this query, but without the [0] index:

SELECT children[0].fname
FROM tutorial
WHERE children[0].age = 17

So, semantically, I want

SELECT children[].fname
FROM tutorial
WHERE children[
].age = 17

(obviously the “*” syntax doesn’t work) I’m guessing this is a pretty basic use case, but I’m struggling with it… I’ve tried array slicing notation ([0:]), but that doesn’t seem to help. Help please?

Hi,

Please use

SELECT c.fname
FROM tutorial t UNNEST t.children c
WHERE c.age = 17

2 Likes

Excellent - that’s what I needed. Thanks geraldss!

Thanks @geraldss. Exactly thats what i needed.

1 Like