Missing vs null
Reference group: BSON types and field properties
What it does
Missing means no field; null means the field exists with BSON null. {field: null} matches both.
Syntax
Use $exists and $type
Use case
Optional fields and accurate filters.
Missing vs null: practical example
db.users.find({ nickname: { $exists: true, $type: "null" } })💡 Explanation
Missing means no field; null means the field exists with BSON null.
{field: null} matches both.
When to use it
Optional fields and accurate filters.Key Takeaways
- Missing means no field; null means the field exists with BSON null.
{field: null}matches both. - Typical use: Optional fields and accurate filters.