Hi Team,
can you please explain where it is going wrong. i am facing below error.
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.
Hi, [A.S.B.PRIYA_TF_RCC
still it is not working and giving similar error.
db.zips.find({"$and" : [{“pop” : {"$gt" : 1000000}}, {“pop”:{"$lt" : 5000 }}]}).count()
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()
11158
MongoDB Enterprise atlas-7aawne-shard-0:PRIMARY> db.zips.find({"$and":[{“pop”:{"$lte":1000000}},{“pop”:{"$gte" : 5000}}]}).count()
11158.
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.
Hi [A.S.B.PRIYA_TF_RCC]
Thanks, Priya…
Below worked for me. check if it works for you.
db.zips.find({"$nor": [{ “pop”:{ “$gt”: 1000000 } },{ “pop”: { “$lt”: 5000 } }]}).count()
11193 .
Yes !! It was the correct answer.
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()
11193
yes, it is correct. we need to use “$nor” here. no need to use “$or”
db.zips.find({"$nor": [{ “pop”:{ “$gt”: 1000000 } },{ “pop”: { “$lt”: 5000 } }]}).count()
11193 .
we need to use “$nor” . no need to use “$or”
{ “pop”:{ “$gt”: 1000000 } } - population of more than 1,000,000 to be over- populated
{ “pop”: { “$lt”: 5000 } } - less than 5,000 to be under-populated
“$nor” - Fail to match both clauses.
db.zips.find({"$nor": [{ “pop”:{ “$gt”: 1000000 } },{ “pop”: { “$lt”: 5000 } }]}).count()
11193 .