I have a invoice collection
, in which I want find the document with a specified book's id.
db.invoice.find({"sold": {$elemMatch: {"book":{$elemMatch:{"_id":"574e68e5ac9fbac82489b689"}}}}})
I tried this but it didn't work
{
"_id" : ObjectId("575e9bf5576533313ac9d993"),
"sold" : [
{
"book" : {
"_id" : "574e68e5ac9fbac82489b689",
"price" : 100,
},
"quantity" : 10,
"total_price" : 1000
}
],
"date" : "13-06-2016"
}