Course M001, chapter 4, wrong lecture notes in it

Question: Find all documents where the student in class 431 received a grade higher than 85 for any type of assignment:
My Finding: Below is the wrong query given in training.

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

Total rows - 182

Right answer:


total rows - 87

This query as given doesn’t make a lot of sense really. It’s using what should be part of the query as the fields to project. Basically the above query returns any document that has a class_id of 431 and that’s why you get a count of 182. Your query is the correct way to return only the document that meet the full criteria of class_id = 432 and a grade higher than 85 for any assignment.

Thanks, Doug_Duncan for the response and spending your valuable time on my query request. Much appreciated.

1 Like