Visit complete MongoDB roadmap

← Back to Topics List

Element Operators

Element operators in MongoDB are used to query documents based on the presence, type, or absence of a field and its value. These operators offer a flexible approach to querying the data and allow you to manipulate elements at a granular level.

Here’s a brief summary of different element operators available in MongoDB.


The $exists operator checks if a field is present or not in a document. Use this operator when you want to filter documents based on the existence of a specific field, regardless of the field’s value.


To query all documents where the field “age” exists:

db.collection.find({ age: { $exists: true } });


The $type operator filters documents based on the data type of a field’s value. This operator can be handy when you need to retrieve documents with value types such as String, Number, Date, Object, and Array.


To query all documents where the field “age” is of type “number”:

db.collection.find({ age: { $type: 'number' } });

Combining Element Operators

You can combine multiple element operators to create more specific queries.


To query all documents where the field “age” exists and its value type is “number”:

db.collection.find({ age: { $exists: true, $type: 'number' } });

In summary, element operators in MongoDB provide a way to query documents based on their field properties. By using $exists, $type, and other similar operators, you can create complex and expressive queries to extract the exact data you need from your collections.

Community is the 6th most starred project on GitHub and is visited by hundreds of thousands of developers every month.

Roadmaps Best Practices Guides Videos Store YouTube by Kamran Ahmed

Community created roadmaps, articles, resources and journeys to help you choose your path and grow in your career.

© · FAQs · Terms · Privacy


The leading DevOps resource for Kubernetes, cloud-native computing, and the latest in at-scale development, deployment, and management.