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.

CategoryBSON Types
MongoDB Version1.0+
Example Languagemongosh (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

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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏