Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB: Find a document by non-existence of a field?

Tags:

mongodb

People also ask

How do you check if a field does not exist MongoDB?

In MongoDB, we can check the existence of the field in the specified collection using the $exists operator. When the value of $exists operator is set to true, then this operator matches the document that contains the specified field(including the documents where the value of that field is null).

How do I search for null values in MongoDB?

The { item : null } query matches documents that either contain the item field whose value is null or that do not contain the item field. The query returns both documents in the collection.

How do you check if a document already exists in MongoDB?

In MongoDB, you can check the existence of the field in the defined collection using the $exists, operator. Here, if the value of the $exists operator is true then the operator matches the document that holds the specified field( including the documents where the value of that field is null).


Try the $exists operator:

db.mycollection.find({ "price" : { "$exists" : false } })

and see its documentation.