The $nor operator performs a logical NOR on an array of query conditions. A document matches only when none of the conditions are true — the opposite of $or.
01
Logical NOR
None may match.
02
Array Syntax
Full conditions in array.
03
Query Operator
find() and $match.
04
Multi-Field
Cross-field exclusions.
05
Use Cases
Blocklists, eligibility.
06
vs $or
Opposite of OR logic.
Fundamentals
Definition and Usage
In MongoDB, the $nor operator selects documents where no sub-expression in its array matches. Think of it as: “exclude documents that satisfy condition A or condition B.” Formally, $nor is equivalent to NOT (A OR B OR ...).
This is especially useful when exclusion rules span different fields. For example, keep products that are neither out of stock nor priced below $10.
💡
Beginner Tip
$nor is a query operator for find() and $match. It is not an aggregation expression like $and or $or in $project. For NOR logic inside $expr, use { $not: { $or: [ ... ] } } instead.
Foundation
📝 Syntax
The $nor operator takes an array of query expressions:
$nor is not an aggregation expression operator. Inside $expr, wrap an $or with $not to achieve the same logical result with field-level comparisons.
Applications
🚀 Use Cases
Catalog filtering — exclude products that are out of stock or below a minimum price.
User eligibility — block users who are inactive or below a minimum age.
Order cleanup — remove cancelled, refunded, or invalid orders before reporting.
Complex exclusions — combine unrelated field conditions in one filter.
🧠 How $nor Works
1
MongoDB evaluates each condition
Every expression in the $nor array is tested against each document.
Input
2
$nor checks for zero matches
If any condition matches, the document fails. All conditions must fail for the document to pass.
Logic
3
Matching documents continue
In find() or $match, only documents where none of the NOR conditions matched are returned.
Output
=
🚫
Clean exclusion filters
Documents matching any blocked condition are removed from results.
Wrap Up
Conclusion
The $nor operator is MongoDB’s logical NOR for query filters. Use it when you need to exclude documents that match any of several independent conditions, especially across different fields.
Remember it is query-only, opposite to $or, and often replaceable by $nin for same-field value lists. Next in the series: $not.
Put each condition in its own object inside the array
Prefer $nin when excluding values on one field
Use $not + $or inside $expr for expression-level NOR
Place $match with $nor early in pipelines
❌ Don’t
Use $nor directly inside $project (it is query-only)
Confuse $nor with $not (single-condition negation)
Forget that one matching condition excludes the document
Overuse $nor when simple $nin or $ne suffices
Mix up $nor (none match) with $and (all must match)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about $nor
Use these points when building exclusion filters in MongoDB.
5
Core concepts
🚫01
Logical NOR
None may match.
Purpose
📝02
Array Syntax
{ $nor: [...] }
Syntax
🔍03
Query Only
find() and $match.
Usage
🔄04
Opposite of $or
NOT (A OR B).
Logic
📑05
Use $nin
Same-field lists.
Alternative
❓ Frequently Asked Questions
$nor performs a logical NOR on an array of query conditions. A document matches only when none of the conditions in the array match. It is equivalent to NOT (condition1 OR condition2 OR ...).
The syntax is { $nor: [ <condition1>, <condition2>, ... ] }. Each element is a full query expression, such as { status: "inactive" } or { price: { $lt: 10 } }.
$nor is a query operator. Use it in find() filters and in the $match stage of aggregation pipelines. It is not available as a standalone aggregation expression operator — use $not with $or inside $expr for similar logic.
$or matches documents where at least one condition is true. $nor matches documents where none of the conditions are true. They are logical opposites when applied to the same condition set.
Use $nin when excluding multiple values from one field: { status: { $nin: ["a", "b"] } }. Use $nor when conditions span different fields or use different operators: { $nor: [ { inStock: false }, { price: { $lt: 10 } } ] }.