To query referenced objects in Node MongoDB, we use $unwind and $lookup.
For instance, we write
db.Foo.aggregate(
{ $unwind: "$bars" },
{
$lookup: {
from: "bar",
localField: "bars",
foreignField: "_id",
as: "bar",
},
},
{
$match: {
"bar.testprop": true,
},
}
);
to call aggregate with $unwind to unwind the $bars entries.
And then we look up the testprop field of the bars entries that’s set to true with $match.