Check the existence filter query
$exists operator shows all the collection documents if they exist on a given key.
Example:
db.article.find({time:{$exists:"true"}}).pretty()
Output:
[
{
_id: ObjectId('60095fd4e5a7731b2a55a922'),
title: 'Trie',
author: 'Rakesh',
length: 500,
example: 20,
time: 50
}
]
In the above Query, We have documents which has the attribute named as time by passing a filter query that is {time : {$exists : “true”}} in the find() method.
What is a MongoDB Query?
MongoDB Query is a fundamental aspect of MongoDB that allows users to fetch data from the database. Similar to SQL queries in traditional databases, MongoDB queries provide simplicity and flexibility in retrieving specific data based on certain criteria or conditions.
In this article, We will learn about the MongoDB Query in detail by performing various Queries on document of MongoDB collection and so on.
Contact Us