I’m new to mongodb and am trying to query child objects. I have a collection of States, and each State has child Cities. One of the Cities has a Name property that is null, which is causing errors in my app. How would I query the State collections to find child Cities that have a name == null?
Share
If it is exactly
null(as opposed to not set):(but as javierfp points out, it also matches documents that have no cities array at all, I’m assuming that they do).
If it’s the case that the property is not set:
I’ve tested the above with a collection created with these two inserts:
The first query finds the first state, the second query finds the second. If you want to find them both with one query you can make an
$orquery: