$not (aggregation)
On this page
Definition
-
$not
-
Evaluates a boolean and returns the opposite boolean value; i.e. when passed an expression that evaluates to
true
,$not
returnsfalse
; when passed an expression that evaluates tofalse
,$not
returnstrue
.$not
has the following syntax:For more information on expressions, see Expressions.
Behavior
In addition to the false
boolean value, $not
evaluates as false
the following: null
, 0
, and undefined
values. The $not
evaluates all other values as true
, including non-zero numeric values and arrays.
Example | Result | |
---|---|---|
{ $not: [ true ] } |
false |
|
{ $not: [ [ false ] ] } |
false |
|
{ $not: [ false ] } |
true |
|
{ $not: [ null ] } |
true |
|
{ $not: [ 0 ] } |
true |
Example
Consider an inventory
collection with the following documents:
The following operation uses the $not
operator to determine if qty
is not greater than 250
:
The operation returns the following results: