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$neoperator is used to match documents where the field does not equal the specified value.
Helpful links
More of Mongodb
- How to use unwind in MongoDB?
- How to use watch in MongoDB?
- How to use triggers in MongoDB?
- How to empty an array in MongoDB?
- How to use transactions in MongoDB?
- How to check the version of MongoDB?
- How to work with time series data in MongoDB?
- How to update many documents in MongoDB?
- How to list MongoDB users?
- How to select specific fields in MongoDB query?
See more codes...