Chapter 3 IDE quiz question

SPOILER ALERT: This post reveals a solution the Chapter 3’s IDE space quiz question.

I’ve solved the quiz question using these two queries, is there a single line solution as well? maybe something like an if-else statement?

db.zips.updateMany({"city":"ALBANY", "state":"NY"}, {"$set": {"capital?": true}})
db.zips.updateMany({"city":"NEW YORK", "state":"NY"}, {"$set": {"capital?": false}})

There was no solutions for the quiz on its page, or at least I couldn’t find it, so thanks for your help.

P.S: BTW, sorry this is a different question but, is there a way to do the “.count()” in the Atlas’ data explorer as well? It currently says MANY for all queries (even for one which returned 21 documents!) which is a bit annoying. Thanks in advance.

Hi @Ader_Chox,

Welcome to the MongoDB Community Forum,

Yes there is a way to solve this question in a single line query by using MongoDB aggregations i.e., $cond operator.

Here, You will have to do that in two distinct queries by using MongoDB Query language, just like you did it. :100:

As per the current version of Atlas, there is no way to do count() by using Atlas data explorer on the browser, but yeah using MongoDB Compass you can.
:point_down:

Hope it helps…!!
Feel free to reach out for any further questions.

Thanks
Kushagra

1 Like