Chapter 4 Lab 1: Logic Operators

Hi all,

Would like to know if someone could explain to me what is the difference between these two filters and their different results:

{"pop": {"$gt": 5000}, "pop": {"$lt": 1000000}}

{"pop": {"$gt": 5000, "$lt": 1000000}}

Thanks in advance.

A query is a JSON document. In a JSON document you cannot have two fields with the same name. In the first case, pop appears twice. The second occurence overwrite the first so your query becomes {"pop": {"$lt": 1000000}}.

Try a = {"pop": {"$gt": 5000}, "pop": {"$lt": 1000000}} in mongo shell to see the result.

1 Like