I am looking for a way to request a collection as follows:
[{ name: "Parent 1", items: [ { name: "Child 1", age: "60" }, { name: "Child at heart", age: "27" } ] }, { name: "Parent 2", items: [ { name: "Child 3", age: "10" }, { name: "Child 4", age: "15" }, { name: "Child at heart", age: "60" } ] } ]
With such a request:
db.collection.find( 'items.name' => "Child at heart", 'items.age' => "60" )
And get the result of only the object named "Parent 2". That is, I want to query documents that search for those that contain an inline element that has both the name “Child at heart” and age “60” in the same inline document. Instead, this query returns both documents: “Parent 1” and "Parent 2".
How do I execute a query using $ and conditions for different fields inside the same embedded document?
Thanks.
source share