Articles → MONGODB → $Size Operator In Mongodb$Size Operator In MongodbIn this article, we will discuss the $size operator in MongoDB.Purpose The $size operator in MongoDB returns documents that contain an array field matching the specified size provided in the argument. It filters documents based on the exact number of elements present in the array field.Example Consider the following collection: -We require to get the employees having exactly 3 hobbies. So, the query will be: -db.Employees.find({ "hobbies": { $size: 3 } })Output Posted By - Karan Gupta Posted On - Thursday, March 7, 2024 Query/Feedback Your Email Id** Subject* Query/Feedback Characters remaining 250**
db.Employees.find({ "hobbies": { $size: 3 } })
Query/Feedback