Null (Empty Value)
Last updated: 2026-10-09
Null (Empty Value)
Null means the field holds an empty value, distinct from a missing field. A query like `{ field: null }` matches both null values and missing fields; combine with `$exists` to tell them apart. Convention: null = explicitly empty, missing = never set.
| Category | BSON Types |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
{ field: null }
db.users.find({ field: null })
db.users.find({ field: { $eq: null, $exists: true } })
Returns:The null value itself; queries return matching documents
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// Null: null value vs missing field
use shop
db.users.find({ phone: null })
db.users.find({ phone: { $eq: null, $exists: true } })
Output:
// First: users whose phone is null or missing. Second: only those with phone null
📌 Notes
- null and missing are different states with different semantics
- { field: null } equals { field: { $eq: null } } and includes missing fields
- Empty string '' is a string value and never matches null
🏷️ Related Tags
💡 Related Cases
More hands-on cases coming soon.
📚 Related Tutorials
❓ FAQ
QDoes querying null return documents where the field is missing?
AYes. { field: null } matches both null values and missing fields.
QIs null the same as an empty string ''?
ANo. '' is a string value while null is empty; queries for one never match the other.
QHow do I match only documents where the field is null?
AUse { field: { $eq: null, $exists: true } } so $exists excludes missing fields.