Query operator - logic $and

In the lecture about query operator - logic, Instructor says following are same but looks like 2nd option does not and throw errors.

  1. db.grades.find({"$and": [{"student_id": {"$gt": 25}}, {"student_id": {"$lt": 100}}]}).count()

  2. db.grades.find({"student_id": {"$gt": 25}}, {"student_id": {"$lt": 100}})

  3. db.grades.find({"student_id": {"$gt": 25, "$lt": 100}})

When running the 2nd query throwing error.

db.grades.find({"student_id": {"$gt": 25}}, {"student_id": {"$lt": 100}})
Error: error: { "ok" : 0, "errmsg" : "Unsupported projection option: student_id: { $lt: 100.0 }", "code" : 2, "codeName" : "BadValue" }


You must have a typing error in the second query. You have an extra closing brace after $gt:25 so your query ends right there. The second object ( with the key student_id ) is taken as the projection parameter of the find method.

1 Like

Hi @Pirathapan_09074 ,

I hope you found @steevej-1495’s response helpful.

Let us know if you still have any questions.

~ Shubham