Assume that for the collection name and field for the field name, the field "n" is added:
> db.coll.insert({n:1, field:1}); // should NOT find > db.coll.insert({n:2}); // should find > db.coll.insert({n:3, field:null}); // should find > db.coll.insert({n:4, field:[1,2,3]}); // should NOT find > db.coll.insert({n:5, field:[1,2,null]}); // should find > db.coll.find({field:null}); { "_id" : ObjectId("503f089a1edeba307d051fbd"), "n" : 2 } { "_id" : ObjectId("503f089e1edeba307d051fbe"), "n" : 3, "field" : null } { "_id" : ObjectId("503f08b01edeba307d051fc0"), "n" : 5, "field" : [ 1, 2, null ] }
Update: Leftium is really right; you only need db.coll.find({field:null}); . I am also updating my answer to reflect this.
source share