Put one expression inside the aggregation array form.
Prefer $ne for simple “not equal to this value” checks.
Piece
Required?
Role
Query form
—
{ field: { $not: { op... } } }
Expression form
—
{ $not: [ expr ] } → boolean
Inner condition
Yes
What you want to invert
Pseudocode
Pseudocode
// Filter mode
for each document:
if NOT (field matches operator-expression):
keep document
else:
drop document
// Expression mode
for each document:
result = NOT evaluate(expression) // true ↔ false
emit { ..., field: result }
Reference
Cheat Sheet
Keep these facts handy while writing NOT conditions.
Topic
Detail
Meaning
Logical NOT / invert a condition
Query syntax
{ field: { $not: { $lt: 10 } } }
Agg syntax
{ $not: [ <expression> ] }
vs $ne
$ne = not equal to a value
Missing field
Query $not can match docs without the field
Agg falsey
false, null, 0, undefined
Sample check
price: { $not: { $lt: 10 } } keeps 15, drops 5
Try it
Live Preview
Watch query $not test “price is not less than 10”.
Wrap with $not. Aggregation form needs an array: { $not: [ ... ] }.
Flip the boolean. Pen: not (5>10) → true. Book: not (15>10) → false.
Nothing is dropped. Both rows stay; only the flag differs.
Edge Cases & Pitfalls
Check these before using $not in production queries.
missing
Missing fields can match
Query $not may keep documents that do not have the field. That differs from $lte, which usually requires the field.
syntax
Agg form needs an array
Write { $not: [ expr ] }, not a bare expression. Query form wraps an operator under a field name instead.
ne
Prefer $ne for simple inequality
{ status: { $ne: "archived" } } is clearer than { status: { $not: { $eq: "archived" } } }.
falsey
Agg treats 0 and null as false
In aggregation, $not of 0 or null is true. Non-zero numbers count as true.
Analysis
Performance Notes
Approach
Cost
Best for
Positive range ($gte)
Often clearer / index-friendly
When equivalent to negated $lt
Query $not
Depends on inner op + missing fields
Negating regex / complex operators
Agg boolean $not
Per-document flip
Flags without dropping rows
When $not: { $lt: x } is logically “≥ x” for existing numbers, consider writing $gte directly for clearer intent.
Remember
Key Takeaways
Role: logical NOT — invert a condition or boolean.
Query:{ field: { $not: { op... } } }.
Expression:{ $not: [ expr ] } → boolean.
Tip: use $ne for simple “not equal”.
One line:$not answers “is this condition false?”—as a filter or as a boolean.
Frequently Asked Questions
$not negates a condition. In queries it inverts an operator on a field: { price: { $not: { $lt: 10 } } } matches prices that are not less than 10. In aggregation it returns the opposite boolean of an expression.
Query form: { field: { $not: { <operator-expression> } } }. Aggregation form: { $not: [ <expression> ] }. The aggregation form wraps one expression in an array.
$ne compares a field to one value: { status: { $ne: "archived" } }. $not negates an operator expression: { price: { $not: { $lt: 10 } } }. Prefer $ne for simple inequality.
$not negates one operator expression on a field. $nor takes an array of separate conditions and matches when none of them match. Use $nor for multiple independent exclusions.
Yes. Documents that do not contain the field can match a $not condition. That differs from $lte / $gte, which usually require the field to exist.
false, null, 0, and undefined are treated as false (so $not returns true). Other values—including non-zero numbers and arrays—are treated as true.