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 use watch in MongoDB?
- How to check the version of MongoDB?
- How to use triggers in MongoDB?
- How to use unwind in MongoDB?
- How to list MongoDB users?
- How to do text search in MongoDB?
- How to update one document in MongoDB?
- How to rename a field in MongoDB?
- How to update many documents in MongoDB?
- How to rename a MongoDB collection?
See more codes...