Select MongoDB documents where a field either does not exist, is null, or is false?
You can do this with $in
:
db.fruits.find({is_reported: {$in: [null, false]}})
returns:
{ "_id": 1, "name": "Apple"}{ "_id": 2, "name": "Banana", "is_reported": null}{ "_id": 3, "name": "Cherry", "is_reported": false}
You could also flip things around logically and use $ne
if you don't have any values besides true
to exclude:
db.fruits.find({is_reported: {$ne: true}})