Select with nested collections

Asked by Raleigh Thompson on 2019-02-03

How do I construct a query when filtering on a nested collection attribute?

sample data
{"a": [
{"b": "1","c": "1st","e": [{"r": "1","t": "dd"}, {"r": "3","t": "ee"}]},
{"b": "1","c": "2nd","e": [{"r": "4","t": "gg"}, {"r": "5","t": "kk"}]},
{"b": "1","c": "3rd","e": [{"r": "3","t": "hh"}, {"r": "7","t": "pp"}]}
]}

I'm trying to build a query to return a list of a items where the inner collection matches e{r==3}.

So the expect result
[
{"b": "1","c": "1st","e": [{"r": "1","t": "dd"}, {"r": "3","t": "ee"}]},
{"b": "1","c": "3rd","e": [{"r": "3","t": "hh"}, {"r": "7","t": "pp"}]}
]
I can build queries the return the inner list but can't figure how to get the outer collection attributes.

Using http://yaqluator.com/
query: $.a.where($.e.where($.r="3"))
result:
All of the elements in a are returned.

Question information

Language:
English Edit question
Status:
Solved
For:
YAQL Edit question
Assignee:
No assignee Edit question
Solved by:
Raleigh Thompson
Solved:
2019-02-03
Last query:
2019-02-03
Last reply:

** Resolved Issue 2019-02-03 **
query: $.a.where($.e.any($.r="3"))