2
votes

I'm trying to run a MongoDB query and return those records where a field is null (more specifically None in pyMongo). So it has to be equal to null.

I know this is not equal to:

{"firstName": {"$ne": None }}

I can't find the equal operator in the documentation.

Thanks

4

4 Answers

5
votes
2
votes

If you want to find records having firstName defined in record with value None defined:

db.testcoll.find({$and: [{"firstName": None}, {"firstName": {$exists: true}}]})
0
votes

If I understand correctly it should be just:

{"firstName": None}

With yours you are getting all the documents that have a value different of None. {"firstName": {"$ne": None }}

0
votes

Use {"firstName": { "$exists": false }} to find records where there's no such field.