When you search MongoDB null
and missing values are equivalent.
> db.foo.insert({a: null})
> db.foo.insert({})
db.foo.find({a: null}, {_id: 0})
{ "a" : null }
{ }
It works the same way with pymongo
:
>>> [doc for doc in pymongo.MongoClient().test.foo.find({'a': None}, {'_id': 0})]
[{u'a': None}, {}]
So None
seems to be a good choice. It is consistent with Python semantics, it plays nice with default behavior of dict.get
method and maps intuitively to MongoDB types when using Python driver.