$nor (Logical NOR)
Last updated: 2026-10-09
$nor (Logical NOR)
$nor combines predicates; a document matches only when none of them hold. `{ $nor: [ { price: 1.99 }, { sale: true } ] }` matches products that are neither $1.99 nor on sale — the inverse of $or. Pitfall: a missing field fails each condition, so $nor silently includes documents missing the fields.
| Category | Logical |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
{ $nor: [ { <condition1> }, { <condition2> }, ... ] }
⚙️ Parameters
| conditions array | An array of query predicates; none of them may hold. |
|---|
Returns:Cursor of matching documents
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// $nor: price is not 1.99 and not on sale
db.products.find({
$nor: [
{ price: 1.99 },
{ sale: true }
]
})
Output:
// Returns products neither $1.99 nor on sale; note documents missing the sale field also match
📌 Notes
- A missing field fails each condition, so $nor includes missing-field documents (classic pitfall)
- To exclude missing fields, add $exists: true to each condition
- $nor negates multiple predicates; $not negates a single field operator
🏷️ Related Tags
💡 Related Cases
Document Query Basics: The `find` Method and Projections
Query Operators: A Complete Guide to the 30+ Operator
📚 Related Tutorials
❓ FAQ
QWhat is the difference between $nor and $not?
A$nor requires none of several predicates to hold; $not negates one operator expression.
QWhy does $nor return documents missing the field?
AA missing field satisfies no condition, and $nor requires none to hold — so those documents are included.
QCan $nor nest $or?
AYes, each element inside $nor can be a complex predicate.