{
tests: [
{ grade: 90 },
{ grade: 80 },
{ grade: 100 },
...
]
}
This is the schema of my collection.
I have an index on tests.grade
.
In my aggregation pipeline, after $elemMatch
inside of a $match
, there will be
[
{ $match: { tests: { $elemMatch: { grade: { $gt: 50 } } } } },
{ $sort: { "tests.grade": 1 } },
{ $limit: 10 }
]
My question is, will this work, given that tests.grade
is a field inside of an array of embedded documents? Would it know to use the embedded doc that was matched in the elemMatch
? What if there are multiple matches? Would this be optimized as in ESR rule?