will the below MQL will return the same results? If yes, then why? Score is a field inside Grades array.
{$and:[{“grades.score”:{$gt:80}},{“grades.score”:{$lt:100}}]}
{grades : { $elemMatch:{“score”:{$gt : 80 , $lt :100}}}}
will the below MQL will return the same results? If yes, then why? Score is a field inside Grades array.
{$and:[{“grades.score”:{$gt:80}},{“grades.score”:{$lt:100}}]}
{grades : { $elemMatch:{“score”:{$gt : 80 , $lt :100}}}}
No they won’t.
With $elemMatch you ensure that both conditions are true within the same element.
While the first one will also match documents that have one element of grades with scores:{$gt:80} and another with score:{$lt:100}.