- Reference >
- Operators >
- Aggregation Pipeline Operators >
- Boolean Aggregation Operators >
- $and (aggregation)
$and (aggregation)¶
On this page
Definition¶
-
$and¶ Evaluates one or more expressions and returns
trueif all of the expressions aretrueor if evoked with no argument expressions. Otherwise,$andreturnsfalse.$andhas the following syntax:For more information on expressions, see Expressions.
Behavior¶
$and uses short-circuit logic: the operation stops
evaluation after encountering the first false expression.
In addition to the false boolean value, $and evaluates
as false the following: null, 0, and undefined
values. The $and evaluates all other values as true,
including non-zero numeric values and arrays.
| Example | Result | |
|---|---|---|
{ $and: [ 1, "green" ] } |
true |
|
{ $and: [ ] } |
true |
|
{ $and: [ [ null ], [ false ], [ 0 ] ] } |
true |
|
{ $and: [ null, true ] } |
false |
|
{ $and: [ 0, true ] } |
false |