Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Hey learners, the word "exists" means that something is present. With the help of the $exists operator, we can check whether a document is present or not. With the help of the $exists operator, we can easily retrieve and filter our documents based on the presence or absence of specific fields.
Let's try to learn the use of the $exists operator and how we can use this in our daily life.
MongoDB Exists
The '$exists' operator in MongoDB is a handy way to check whether a specified field exists in any document or not. When it shows the true, it means that the particular document is present, and when the $exists operator value is set to the false, this returns nothing.
Syntax
{field: {$exists: <bool_value>}}
Parameters
"field" shows what field you are trying to find in a collection.
$exists is the operator which takes the boolean value (true or false).
True returns all documents where the given field exists.
False returns documents where the given field does not exist.
Examples
We’ll do all the operations on the below student collection.
In this, we use the $exists operator to find the data where the 'name' field exists. We are using the below query to find the data collection where the 'name' field exists.
Above, we are using the $exists operator to select the documents from the “student” collection where the “name” field exists.
We can also find the existing field with a condition. So now let's find the documents whose "age" is greater than 18 and whose name exists. Below is the query we use to find the documents with a given condition.
Above, we found all those documents whose names and ages are greater than 18 exist in the student collection.
Without Specified Field
Using the $exists operator, we can also find the data where the 'name' field doesn't exist. Below is the query to find the collection of data where the 'name' field doesn't exist.
This query returns all users who have a city field within their address field.
Combining $exists with Other Operators
You can combine $exists with other query operators to refine your search. For example, to find users who have an email field and their age is greater than 25:
This query updates all users who have an email field, adding the verified field set to true.
Frequently Asked Questions
What’s the purpose in MongoDB of the $exists operator?
The $exists operator in MongoDB checks the existence or absence of a specific field in a document.
What’s the syntax of the $exists, operator?
The syntax of $exists operator is {field: {$exists: <boolean> } }.
Can the $exists operator be used in combination with other operators?
Yeah, you can use the $exists operator with other query operators to create more complex and targeted searches.
Can we use the $exists operator with nested fields in MongoDB?
Yes, the $exists operator can be used with nested fields. The field path can include dot notation to specify nested fields within a document.
Does the $exists operator work with partial matching in MongoDB?
No, the $exists operator does not work with partial matching. It only checks for the existence or absence of fields.
Conclusion
In this article, we discussed the $exists operator and learned how to use this operator to check whether the document exists with the given field or not. We hope this blog helped you to enhance your knowledge of the $exists operator in MongoDB. Check the below articles to know more.
But suppose you have just started your learning process and are looking for questions from tech giants like Amazon, Microsoft, Uber, etc. For that purpose, take a look at the problems, interview experiences, and interview bundles for placement preparations.
However, you may consider our paid courses to give your career an edge over others!
Happy Learning!
Live masterclass
Crack GenAI Skills to ace 30 LPA+ roles at Amazon & Google
by Sumit Shukla
16 Feb, 2026
03:00 PM
Zero to Google Data Analyst: Roadmap for 30L+ CTC
by Prashant
15 Feb, 2026
06:30 AM
Beginner to GenAI Engineer Roadmap for 30L+ CTC at Amazon
by Shantanu Shubham
15 Feb, 2026
08:30 AM
Data Analysis for 20L+ CTC@Flipkart: End-Season Sales dataset
by Sumit Shukla
16 Feb, 2026
01:30 PM
Crack GenAI Skills to ace 30 LPA+ roles at Amazon & Google