KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
> 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" : { "d1" : [ "e1" ], "d2" : [ "e2" ], "d3" : [ "e3", "e4" ], "d4" : [ "e5", "e6" ] } } } } But none of these work: > db.test.find({'a.b': "c"}) > db.test.find({'a.b': {$elemMatch : {"c" : {$exists: true}}}}) > db.test.find({'a.b': {$elemMatch : {$elemMatch : {$all : ["e1"] }}}}) Suppose I don't know what the values of c and d1 ... d4 are. Is there a generic way to search the nested-objects' structure for particular values? I thought that was what $elemMatch was for. Thank you.
Tags (comma-separated)
Save Edits
Cancel