A query returns results that do not match the query conditions?

In the video on Array Operators and Projection, the instructor cites the following query:

db.grades.find({ "class_id": 431 },
               { "scores": { "$elemMatch": { "score": { "$gt": 85 } } }

However, this query returns several documents that do not seem to match the query conditions. Specifically, the document with { “_id” : ObjectId(“56d5f7ec604eb380b0d8f8ea”) } is one of those returned, but on further examination, it shows no scores greater than 85. What’s up with that??? TIA for your reply!

Hi @James_Mortenson,

Kindly allow us some time, till we take a look.
And, please be assured we will provide complete info regarding your query.


Your braces are wrong.

Your first closing brace (after the value 31) terminates the object. So your query is simply { "class_id": 431 }. The rest is not part of your query. It is the 2nd argument to find().


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.