MongoDB Exists Operator

Mongodb exists operator checks the existence of field in the specified collection.

Syntax of Exists

{ field: { $exists: boolean }}

If $exists is true, it matches the document that contains the field and if $exists is false, it returns only the documents that do not contain the field.

Example

Suppose, we want to find all students whose class exists.

db.students.find({"class" : {$exists : true}});
mongodb exists





Read more articles


General Knowledge



Learn Popular Language