null
noun
say it: “NULL” /ˈnʌl/
A special value that means 'no value'; in a MongoDB filter, asking for null also finds documents that don't have the field at all.
What does null match in a MongoDB filter?
null is a value that means "no value". In a MongoDB filter, { field: null } matches documents where that field holds null and also documents that don't have the field at all; $exists tells the two apart.
db.recipes.insertMany([{ name: "Toast", notes: null }, { name: "Tea" }]);
db.recipes.find({ notes: null }, { _id: 0, name: 1 });
// [ { name: 'Toast' }, { name: 'Tea' } ]
In a sentence
- “Searching for notes equal to null found the recipes with empty notes and the ones with no notes field.”
- “The form saved null for a missing phone number instead of leaving the field out.”
Level: Apprentice · More MongoDB terms at this level
Updated