Chapter 4: Advanced CRUD Operations Lab 1: detailed answer

The question is:

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.

The detailed answer shown is:

db.zips.find({ "pop": { "$gt": 5000, "$lt": 1000000 }}).count()

According to the question, a population of exactly 1,000,000 would not be considered over-populated, neither would exactly 5,000 be under-populated. Surely the correct answer is to this question is therefore:

db.zips.find({ "pop": { "$**gte**": 5000, "$**lte**": 1000000 }}).count()

1 Like

Hi @Mark_W,

Welcome to the MongoDB Community Forum :sparkles:

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

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.

But, I will go ahead and include the edge cases in our detailed answer to avoid such confusion in future.

Kushagra Kesav

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.