$ne
The `$ne` operator retrieves documents where the value of a field doesn't equal a specified value.
Syntax
{ field: { $ne: value } }
Parameters
field
stringrequiredThe field to be compared
value
stringrequiredThe value that the field shouldn't be equal to
Examples
Find stores whose name isn't "Fourth Coffee"
To find stores with a name that isn't "Fourth Coffee", run a query using $ne on the name field.
Query:
db.stores.find({
name: { $ne: "Fourth Coffee" }
}, { _id: 1, name: 1 }, { limit: 1 })
Output:
[{ "_id": "2cf3f885-9962-4b67-a172-aa9039e9ae2f", "name": "First Up Consultants | Bed and Bath Center - South Amir" }]
Find stores with promotion events that aren't in 2024
To find stores with promotions events that don't start in 2024, run a query using $ne on the nested startDate field.
Query:
db.stores.find({
"promotionEvents.promotionalDates.startDate": { $ne: "2024" }
}, { name: 1, "promotionEvents.promotionalDates.startDate": 1 }, { limit: 1 })
Output:
[{ "_id": "2cf3f885-9962-4b67-a172-aa9039e9ae2f", "name": "First Up Consultants | Bed and Bath Center - South Amir" }]