First, let's talk about the use of $elemMatch:
{ _id: 1, results: [[+ ]]
{ _id: 2, results: [[], +/- ] }
$elemMatch is that at least one element in the array matching document satisfies all the conditions in $elemmatch, for example:
db. Scores. Find ({results: { $elemMatch : { $gte : 80 $lt : 85 } } Span class= "p" >})
query result:
{ "_id" : 1, "Results" : [[A] [[+ ]]
To explain it (Multikey Index Bounds):
during a query, the scan range of the index defines a partial index in order to search when more than one index (condition) predicates exists: MongoDBwill attempt to merge the boundaries of these (conditions) predicates, or merge them by the method of intersection
Either by combining the method, in order to produce a relatively small scanning range. given an indexed array field, consider that in one query, multiple (conditional) predicates are specified in an array and Multikey index can be used.
if the $elemMatch has more than one Predicates, MongoDB merges the boundaries of Multikey index. Therefore, there will be $elemmatch that matches at least one element of the array in the document satisfies all the conditions in $elemmatch.
Continue with the above example, one by one the bounds of the conditional boundary:
A boundary greater than or equal to ($gte: 80) is [80,inf];
Less than($LT: 85)the boundary for [-inf,85].
Because of the use of the $Elemmatch organization of multiple conditional queries, MongoDB query boundary is results:[[80,85)].
Multikey Index bounds in MongoDB explains $elemmatch