Articles → MONGODB → $Type Operator In Mongodb$Type Operator In MongodbIn this article, we will discuss the $type operator in MongoDB.Purpose The $type operator searches the document based on the BSON data type.Example Consider the following collection: -In the above collection, we have 2 documents. The first document stores the age in number format and the other one stores age in the string format.We are required to find the document where age is of type number. So, the query would be: -db.Employees.find({age:{$type:'number'}})Similarly, we can find the document that contains the age in the string format.Using Array In Type You can also specify multiple BSON types to query the collection.Posted By - Karan Gupta Posted On - Monday, March 4, 2024 Query/Feedback Your Email Id** Subject* Query/Feedback Characters remaining 250**
db.Employees.find({age:{$type:'number'}})
Query/Feedback