MongoDB find Empty Field in document
Today in the article we shall learn how to query documents when MongoDB Field is empty in a document in a collection.
Updated November 2026: a null vs missing vs empty section, a Mongoose troubleshooting checklist and an FAQ.
We shall verify queries using MongoShell or UI tools like a Compass UI.
We shall also see a query to get all documents where the field is not empty in the mongo collection.
We shall also see all the records which are not empty as well.
We shall also be running the query using the .NET C# mongo driver. If interested to know how to run queries using .NET C# mongo driver please check this article.
Today in this article, we will cover below aspects,
Getting started
I have a sample MongoDB document as below in one of the collections. Here we shall be trying to search all the documents where the State field is empty.

Mongo- Find documents when field is Empty
The below query matches documents that where State field is empty
Query Pattern
{ Field Name : { $eq : "" } }
Example Query
{ State : {$eq : "" } }
Results:
Using Compass

Using Mongo shell
Below sample query using CLI/shell to get fields with empty records,

Note:
In the above query $eq an aggregate query compares two values (support both value and type) and returns:
truewhen the values are matchingfalsewhen the values are not matching
Syntax
{ $eq: [ <expression1>, <expression2> ] }
Mongo- Find documents when field is not Empty
The below query matches documents that where State field is empty
Query Pattern
{ Field Name : { $ne: "" } }
Example Query
{ State : {$ne: "" } }
Results:

Null, missing, undefined and empty string: which one do you actually have?
MongoDB treats a missing field, a field set to null and a field set to an empty string "" as three different states, so one query rarely catches all three. The $eq: "" and $ne: "" filters above only deal with the third state.
Note: Picture a paper form. A missing field is a form with no box for that question.
nullis a box where someone wrote “none”. An empty string is a box that someone filled in with nothing at all. All three look blank from a distance, but they are different answers.
This table shows which stored state each filter matches, using a field called State.
| Stored state | { State: null } | $exists: true | $type: "null" | { State: "" } |
|---|---|---|---|---|
| Field missing | Matches | No match | No match | No match |
| Field is null | Matches | Matches | Matches | No match |
| Field is “” | No match | Matches | No match | Matches |
The usual surprise is in the first column. A filter on null matches both null and missing fields. If you only want real nulls, add a $type check.
What happens to undefined?
A value of undefined in your application code isn’t stored as undefined. Depending on the driver and its settings, you end up with either a missing field or a null. The Node.js driver, for example, has an ignoreUndefined option that changes which one you get. Don’t assume. Check a saved document in mongosh or Compass.
How do you query for “empty-looking” and “not empty”?
To find every empty-looking document, use $or with two conditions: State equals null (which also catches missing) and State equals "".
For the not-empty case, use { State: { $nin: [null, ""] } }. This must exclude missing fields too. A plain $ne: "" still returns documents where State is null or absent, because neither of those equals an empty string.
Why does a Mongoose default not match in a filter?
Mongoose applies a schema default when it reads a document that lacks the field, but the stored document still lacks it. A read by id shows completed: false, yet a filter on completed: false matches nothing, because the server never sees that value.
Existing documents need a one-off updateMany that finds documents where the field doesn’t exist and sets it to the default. New documents are fine, since the default is written on save.
The field is null or Not Set in MongoDB
Please visit the below article for more details,
That’s all, So today we learned the simple mongo query for identifying the records where the field is null or not set. It’s pretty easy to prepare the query for such needs.
References:
Do you have any comments or ideas or any better suggestions to share?
Please sound off your comments below.
Happy Coding !!
Please bookmark this page and share it with your friends. Please Subscribe to the blog to receive notifications on freshly published (2026) best practices and guidelines for software design and development.
Frequently asked questions
Why is only the _id saved to MongoDB when I use Mongoose?
Usually the incoming fields don’t match the schema, so Mongoose’s default strict mode drops them, or the request body wasn’t parsed before it reached your model. Set strict: 'throw' on the schema and Mongoose will raise an error naming the unknown fields instead of silently discarding them. In Next.js with hot reload, the model can be compiled repeatedly, so export the registered model with mongoose.models.User || mongoose.model('User', UserSchema).
Why does Mongoose remove my empty object from the document?
The minimize option is on by default, and it strips empty objects before saving. Set minimize: false on the schema to keep them, or give the field a default of {} so the object exists from the start. In Mongoose 8, minimize also applies when you call save() on an existing document, so empty objects can vanish after an upgrade from Mongoose 7.
What is the difference between null, an empty string and a missing field in MongoDB?
They are three separate stored states. A filter of { field: null } matches both documents where the field is null and documents where it is missing. An $exists check separates present from missing, and an empty string only matches an equality check against ''. Look at the stored document in mongosh or Compass to see which one you actually have.
Why does populate() return null or an empty array for my reference field?
When no document matches the reference, a single reference path becomes null and an array reference path becomes []. The field was probably saved correctly, but the referenced document is missing or the stored id is wrong. Check the raw document in mongosh or Compass first, before you assume the save failed.