Suppose you have several nested objects and lists:
> db.test.insert({"a" : { "b" : { "c" :
{ "d1" : [ "e1" ], "d2" : [ "e2" ], "d3" : [ "e3", "e4" ], "d4" : [ "e5", "e6" ] } } } })
> db.test.find({'a.b.c' : {$exists : true}})
{ "_id" : ObjectId("4daf2ccd697ebaacb10976ec"), "a" : { "b" : { "c" :
} } }
I want to retrieve this document based on the sub-object value:
{'d2': ["e3":"e4"]} or just the existence of the array ["e1"] without knowing the value key 'd1'.
The depth of the structure remains constant, but the keys are unknown.
I thought that chaining a few $elemMatch would work, but it did not retrieve the desired results:
> db.test.find({'a.b': {$elemMatch : {$elemMatch : {$all : ["e1"] }}}})
> db.test.find({'a.b': {$elemMatch : {$elemMatch : {$elemMatch : {$all : ["e1"] }}}}})
- duplicates
-
SERVER-267 Wildcard support in index/query/projection
- Backlog
- is related to
-
MONGOID-4622 Document recursively_embeds_many filtering with elem_match
- Closed
- related to
-
SERVER-736 Support for XPath like queries
- Backlog
-
SERVER-267 Wildcard support in index/query/projection
- Backlog