M001:chapter2:Your Chapter 2 IDE space

M001:chapter2:Your Chapter 2 IDE space
i am not able to get below queries builded
3. Find out how many ZIP codes there are in NY state.
4. What about the ZIP codes that are in NY but also in the city of Albany?

can someone assist to build the query

The above should be the same as

But you want to refine the search so that you only count the one in the city of Albany. Albany is a city in the state of New York. So you want something like:

State is NY and City is Albany.

db.zips.find({“state”: “NY”, “city”: “Albany”}).count()
this will give the count but there can be some documents might not have zip codes for “state”: “NY”, “city”: “Albany” so answer will be wrong in that case.
so we need to modify the above query by adding zip field as well right?

It’s probably not necessary, or it would be requested. But if you want to test, you could try adding zip:{$ne:null} (supposing the field is “zip”).

got it. thanks

1 Like