I am newbie with MongoDb I have a document with this structure :
{
"_id": "570a38612959856808fe9b1d",
"author": "foo",
"books": {
"570a385737000012009e6f65": {
"title": "a1",
"status": "published"
},
"570a385737000012009e6f66": {
"title": "a2",
"status": "pending"
},
"570a385737000012009e6f67": {
"title": "a1",
"status": "published"
}
}
}
how can I search for all authors that have pending books ? I tried something like
{ "books":{$elemMatch:{"status": "pending" }}}
but got nothing
"books": [{ "_id": "570a385737000012009e6f65", "title": "a1", "status": "published" },{..}]Which then makes for simple queties like{ "books.status": "pending" }. Point is that named keys need an "explicit" path, but without them the name of the "path" is the same for all elements.