- Reference >
- Operators >
- Aggregation Pipeline Operators >
- $and (aggregation)
$and (aggregation)¶
On this page
Definition¶
-
$and
¶ Evaluates one or more expressions and returns
true
if all of the expressions aretrue
or if evoked with no argument expressions. Otherwise,$and
returnsfalse
.$and
has 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 |