Chapter 4 Lab 1: Logic Operators

To complete this exercise connect to your Atlas cluster using the in-browser IDE space at the end of this chapter.

How many zips in the sample_training.zips dataset are neither over-populated nor under-populated?

In this case, we consider population of more than 1,000,000 to be over- populated and less than 5,000 to be under-populated.

Copy/paste the exact numeric value of the result that you get into the response field.

1,if u want to get 5000-1,000,000 in range pop , just lt 1,000,000 and gt 5000

2if u want to exculde in the range ,just not lt 1,000,000 and gt 5000

which one result u want to get,or both?

if in the range it is 1****
if out of the range is ****7
or u just want to get more than 1,000,000 or less then 5000 two count number only

i dont know which one is the answer

Over 1,000,000 is over-populated.
Under 5,000 is under-populated.
You want the number that are neither over nor under.
So you want to count those that respect both conditions.
So you do not want to count those above 1,000,000 and you also do not want to count those under 5,000 at the same time.
So it looks like they want you to count the one between 5,000 and 1,000,000.


lte 1,000,000 and gte 5000 right?

but it show wrong

nevermind ,i passed all already


Please take a look at your query that you have share in the screenshot. You aren’t using the right logic operator.

~ Shubham


I’m facing a similar issue, please find the attached screenshot.


I tried both $lt & $gte and $gte and $gt and $lt.


Hi @Niveditha_Karunamurthy,

This means that the given range is an inclusive range. But in your query, you are excluding them by using $lt and $gt query.

~ Shubham

Hi @Shubham_Ranjan,

It works fine now - thanks. Apparently, I modified pop values in the DB, however the answer matches the exact numbers from Sample DB, I had to re-load in order to get this to work using my original syntax.

Same with IDE first test, my Cluster name was different (not Sandbox), so it didn’t accept my connection to the Cluster as valid one. I had to terminate and re-create to match Sandbox.


1 Like

hii ,
you can try the following query
db.zips.find({"$nor":[{“pop”:{"$gt": 1000000 }},{pop: { $lt: 5000 }}]}).count()
and result is 11193

Hi, this worked for me the other day, I had originally modified pop values directly in the DB.


I do believe there is a mistake with the detailed answer. The first answer is db.zips.find({ “pop”: { “$gt”: 5000, “$lt”: 1000000 }}).count(), but this answer would actually exclude zips where the population is exactly 5,000 or 1,000,000. The second accepted answer is db.zips.find({ “$nor”: [ { “pop”: { “$lt”:5000 } },
{ “pop”: { “$gt”: 1000000 } } ] } ).count() but this query would include zips with populations of exactly 5,000 or 1,000,000, which is what the question. actually asked for. The only reason they return the same number is because there just happens to be no zips with a pop of exactly 5,000 or 1,000,000. So the detailed answer appears to suggest the queries are equivalent when they are not.

Hi @Ben_Ryan,

Welcome to the MongoDB Community Forum

Correct…If you’d like to check with exact endpoints, your query could look like:

db.zips.find({ "pop": { "$gte": 5000, "$lte": 1000000 } } ).count() where $gte is described as greater than or equal and $lte - less than or equal

However given the case and known results, since both values - 5,000 and 1,000,000 - are not present in the field, it makes no difference to the lab since it’s all about the resulting number, not the syntax itself.

If there is still any follow-up question, feel free to reach out.


As the lab is about using the correct operators, whether the wrong operators give the correct answer is nether here nor there. In my opinion the detailed answer should be corrected to include the edge cases. It would have stopped me wasting 10 mins searching the forum to see if anyone else had queried this before.

Hi @Steven_Wilson, welcome to the community.
Thanks for your feedback and suggestions, I will forward this to the appropriate team.

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

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer