Solution for PyMongo:
or
db.collection.find({ 'field': float('nan') })
FYI: I ran into this problem because mongoexport (mongo 3.0.7) wrote NaN to the JSON files that it created. This seems to have been reviewed in 3.3.5 .
So, again using PyMongo and in a similar boat, you can replace NaN with Python None , which mongoexport converts to JSON valid null :
import numpy as np for doc in list(db.collection.find({ 'field': np.nan })) update_one({'_id': ObjectId(doc['_id'])}, {'$set': {'field': (lambda x: None if np.isnan(x) else x)(doc['field'])}})
source share