I will use the example from here
{
_id: 1,
zipcode: 63109,
students: [
{ name: \"john\", school: 102, age: 10 },
{ name: \"je
This worked for me in a case of similar filtering. Now I know this question was asked many years ago, but to anyone looking for an answer like me. here's what worked for me. Thanks to original answer!
In the case of this particular question:
outerparam is zipcode and innerarray.property is students.school.
let cursor = db
.collection("somecollection")
.aggregate(
{ $match: { outerparam: outermatch } },
{ $unwind: "$innerarray" },
{ $match: { "innerarray.property": propertymatch } },
{ $project: { "innerarray.$": 1 } });