We know that MongoDB has different types of documents because of schema less Database. Some columns may present in some documents and not present in some other documents.

In this case we can retrieve the data by checking if the specified columns exist are not in the mongo DB.

Using “exists” we can retrieve the documents for which the specified column has exists.

Syntax:            db.collection.find({field:{$exists:bool}})


db.studentDetails.find({Marks:{$exists:true}})

The above Example returns the documents that contain the field ‘Marks’


db.studentDetails.find({Marks:{$exists:false}})

The above Example returns the documents that doesn’t contain the field ‘Marks’