Using the example found at:
https://docs.mongodb.com/manual/tutorial/query-array-of-documents/
Having:
db.inventory.insertMany( [
{ item: "journal", instock: [ { warehouse: "A", qty: 5 }, { warehouse: "C", qty: 15 } ] },
{ item: "notebook", instock: [ { warehouse: "C", qty: 5 } ] },
{ item: "paper", instock: [ { warehouse: "A", qty: 60 }, { warehouse: "B", qty: 15 } ] },
{ item: "planner", instock: [ { warehouse: "A", qty: 40 }, { warehouse: "B", qty: 5 } ] },
{ item: "postcard", instock: [ { warehouse: "B", qty: 15 }, { warehouse: "C", qty: 35 } ] }
]);
and later querying:
db.inventory.find( { "instock": { warehouse: "A", qty: 5 } } )
returns a set of documents having warehouse = A and qty=5 in "instock" subdocument
But querying just for those containing {warehouse: "A"} doesn't return any result
db.inventory.find( { "instock": { warehouse: "A" } } )
Now, changing that to:
db.inventory.find( { "instock.warehouse": "A" })
works out
Shouldn't be both the same ? Anything about the semantics ?
On the other hand, what's the correct way to find for a field value that's in list of subdocuments inside another list of subdocuments (embedded of embedded)
Thanks !