Chapter 4: Advanced CRUD Operations Lab 1: Logic Operators

ch 4 lab 2 Hi Team,

can you please explain where it is going wrong. i am facing below error.

Hello @Pratap_Nayadkar ,

I think you have to close double quotes for $and like … “$and”. Let me know after that also you get error.

still it is not working and giving similar error.
db.zips.find({"$and" : [{“pop” : {"$gt" : 1000000}}, {“pop”:{"$lt" : 5000 }}]}).count()

Hi @Pratap_Nayadkar

I’m also doing basics and don’t have any prior knowledge about Mongodb. I think you may reconsider your logical operator while placing. I had used the following codes for that problem.

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

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

I already posted the same query under Lab Question : Is my query correct? Let me know its help you in anyways to find the solution. If so help me out for that post.


Thanks, Priya…
Below worked for me. check if it works for you.
db.zips.find({"$nor": [{ “pop”:{ “$gt”: 1000000 } },{ “pop”: { “$lt”: 5000 } }]}).count()
11193 .

Hi @Pratap_Nayadkar ,

So you got it correct by entering the value?

Yes !! It was the correct answer.

1 Like

@A.S.B.PRIYA_TF_RCC, as I mentioned in your other post:

You do not get the correct answer here because

you cannot have pop greater than 1000000 and smaller than 5000 at the same time. With you would need to use $lte 1000000 and $gte 5000.

check the above thread. with $nor I got the answer.

db.zips.find({"$nor": [{ “pop”:{ “$gt”: 1000000 } },{ “pop”: { “$lt”: 5000 } }]}).count()