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 MongoDB queue?
- How to rename a MongoDB collection?
- How to use MongoDB pull?
- How to insert new document into MongoDB?
- How to implement one-to-many relation in MongoDB?
- How to drop a database in MongoDB?
- How to implement pagination in MongoDB?
See more codes...