Lab Question : Is my query correct?

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.

MongoDB Enterprise atlas-7aawne-shard-0:PRIMARY> use sample_training
switched to db sample_training
MongoDB Enterprise atlas-7aawne-shard-0:PRIMARY> db.zips.updateMany({ “city”: “HUDSON” }, { “$inc”: { “pop”: -10 } })
{ “acknowledged” : true, “matchedCount” : 16, “modifiedCount” : 16 }
MongoDB Enterprise atlas-7aawne-shard-0:PRIMARY> db.zips.find({"$nor":[{“pop”:{"$gt":1000000}},{“pop”:{"$lt" : 5000}}]}).count()
11158

MongoDB Enterprise atlas-7aawne-shard-0:PRIMARY> db.zips.find({"$and":[{“pop”:{"$lte":1000000}},{“pop”:{"$gte" : 5000}}]}).count()
11158

4.Lab_logical_test

The query looks fine. The fact that the answer is wrong might be related to the modifications you did to the data set.

  1. You $inc the pop field used in the query for 16 documents.
  1. You deleted 39 documents.

So you answer might be off anywhere from 1 to 55 documents. May be more if more changes have been done.

I would recommend that you terminate your cluster and create a new one with fresh data.