Potential Error In Chapter: 4, Lecture: Query Operators - Logic

In Chapter: 4, Lecture: Query Operators - Logic, around the 3:20 mark, it was mentioned that the following two queries are the same.

  1. {$and: [{"student_id": {"$gt": 25}}, {"student_id": {"$lt": 100}}]}

  2. {"student_id": {"$gt": 25}, "student_id": {"$lt": 100}}

But actually they aren’t, the first query checks both the conditions i.e. if the student_id field is greater than 25 and less than 100, but the second query only checks if the student_id is less than 100.
So, the second is actually similar to this query: {"student_id": {"$lt": 100}}.

I ran the following queries to verify the above:

  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}}).count()

And the count returned for both the queries were different.

Screenshot from the lecture video.

Please let me know if this is actually a mistake or I am missing something.

Thanks, @Som_Shekhar_Mukherjee for highlighting this!!

This is not a valid query.

We are working on fixing this course content and we apologize for the inconvenience caused to you


Hi @Som_Shekhar_Mukherjee, welcome to the community.

In case you want to know more about this issue, please take a look at the discussion over here.
Please be rest assured that we are working on fixing the issue and hopefully it should reflect in our future offerings.

In case you have any doubts, please feel free to reach out to us.

Thanks. Regards.
Sourabh Bagrecha,
Curriculum Services Engineer.

Why do you say it’s not a valid query, it works without throwing any errors.

Hi @Som_Shekhar_Mukherjee,

Thanks for asking.

Here, by saying that the following query is not valid, I meant that the output of this

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

meant to be same as the output of the second query i.e.,

db.grades.find({"student_id": {"$gt": 25}, "student_id": {"$lt": 100}}).count() --> 1000

But it’s not…so it’s not the valid one considering the implicit $and.

Hope you got my point…!!!

In case of any further doubts feel free to reach out.

Kind Regards,