Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB equal to

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

like image 292
user94628 Avatar asked Oct 16 '25 13:10

user94628


2 Answers

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

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

like image 198
ltfishie Avatar answered Oct 18 '25 08:10

ltfishie


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

db.testcoll.find({$and: [{"firstName": None}, {"firstName": {$exists: true}}]})
like image 21
Sushant Gupta Avatar answered Oct 18 '25 06:10

Sushant Gupta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!