2

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 回答 4

5

{"firstName":{ $type: 10 } } should give you what you want

http://docs.mongodb.org/manual/faq/developers/#faq-developers-query-for-nulls

于 2012-12-19T15:33:56.140 回答
2

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

db.testcoll.find({$and: [{"firstName": None}, {"firstName": {$exists: true}}]})
于 2012-12-19T15:34:45.410 回答
0

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 }}

于 2012-12-19T15:33:54.597 回答
0

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

于 2012-12-19T15:34:10.383 回答