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).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With