$exists is a MongoDB query predicate that matches documents where a field is present or missing. A field with value null still counts as present.
Remember
$exists = is this field on the document?
{ field: { $exists: true } } // field is present (even if null)
{ field: { $exists: false } } // field is missing
present + value → matches $exists: true
present + null → matches $exists: true
missing field → matches $exists: false
Need a real value? → { field: { $ne: null } }
Remember: true includes null; false means the key is absent.
If you need a real value, add { field: { $ne: null } }.
Piece
Required?
Role
Field path
Yes
Which key to check
$exists
Yes
true = present, false = missing
$ne: null
No
Exclude null (and missing) for real values
Pseudocode
Pseudocode
for each document:
if $exists is true:
keep document if field key is present
// value may be string, number, null, …
if $exists is false:
keep document if field key is absent
// not the same as value === null
Reference
Cheat Sheet
Keep these facts handy while checking field presence.
Topic
Detail
Type
Query predicate (find / $match)
Syntax
{ field: { $exists: <boolean> } }
true
Field present, including null
false
Field missing only
Not for $project
Use $type: "missing" in expressions
Real value pattern
{ field: { $ne: null } }
Not SQL EXISTS
Checks a field, not a subquery
Try it
Live Preview
Pick a document shape and see which $exists queries match. Notice that null still counts as present.
Simulates $exists: true, $exists: false, and $ne: null on an email field.
Result
document = { name: "Ada", email: "[email protected]" }
$exists: true → match
$exists: false → no match
$ne: null → match
Trace
Worked Walkthrough — Missing vs Null
Three people. One has an email, one has email: null, and one has no email field at all.
Ask for absence.$exists: false keeps documents with no email key.
Null is not missing. Grace still has email: null, so she does not match.
Only Alan remains. His document never stored email.
Same in find().db.people.find({ email: { $exists: false } }) is equivalent for filtering.
Edge Cases & Pitfalls
Check these before using $exists in production queries.
null
Null is not missing
$exists: true matches null. Use $ne: null when you need a real value.
agg
Not an expression operator
You cannot put $exists inside $project math. In expressions, use $type: "missing".
sql
Not SQL EXISTS
MongoDB $exists checks a field on the current document. It does not run a subquery existence test.
index
$exists: false is hard to index
$exists: true can use a sparse index efficiently. $exists: false often needs a collection scan—filter early when you can.
Analysis
Performance Notes
Approach
Cost
Best for
$exists: true + sparse index
Often very efficient
Fields present on a minority of docs
$exists: false
Often collection scan
Finding incomplete documents
$ne: null
Index-friendly when indexed
Non-null real values
Prefer early $match filters. If you mostly query “field has a value,” $ne: null is often clearer and more index-friendly than $exists: true alone.
Remember
Key Takeaways
Role: field present (true) or missing (false).
Null: still exists—use $ne: null for real values.
Place: find / $match only (not $project math).
Expressions: use $type: "missing" instead.
One line:$exists answers “is this field on the document?”—not “does it have a useful value?”
Frequently Asked Questions
$exists matches documents that contain or do not contain a specified field. Use { field: { $exists: true } } for present fields, or { field: { $exists: false } } for documents where the field is missing entirely.
Yes. A field stored as null still exists. { email: { $exists: true } } matches both "[email protected]" and null. To require a non-null value, combine with { email: { $ne: null } }.
Missing means the field is not stored at all. Null means the field is stored with an explicit null value. $exists: false matches missing only. $exists: true matches null and non-null values.
$exists is a query predicate operator for find() filters and the $match stage. It is not an aggregation expression for $project. In expressions, check $type against "missing" instead.
No. SQL EXISTS checks whether a subquery returns rows. MongoDB $exists checks whether a field is present on a document.
Prefer { field: { $ne: null } }. That skips both missing fields and explicit nulls. $exists: true alone still includes null.