mongodbHow to query with "not equal" condition in MongoDB?
MongoDB provides the $ne
operator to query documents with "not equal" condition. The $ne
operator matches all the documents that do not contain the specified field value.
Example
db.collection.find({ field: { $ne: value } })
This example will return all documents in the collection where the value of the field does not equal the specified value.
Code explanation
db.collection.find()
: This is the MongoDB query method used to find documents in a collection.{ field: { $ne: value } }
: This is the query condition used to specify the field and value to match. The$ne
operator is used to match documents where the field does not equal the specified value.
Helpful links
More of Mongodb
- How to check the version of MongoDB?
- How to use watch in MongoDB?
- How to update one document in MongoDB?
- How to update many documents in MongoDB?
- How to use MongoDB queue?
- How to create a many to many relation in MongoDB?
- How to insert new document into MongoDB?
- How to use hint in MongoDB?
- How to work with time series data in MongoDB?
- How to use unwind in MongoDB?
See more codes...