$or (aggregation)
On this page
Definition
-
$or
-
Evaluates one or more expressions and returns
true
if any of the expressions aretrue
. Otherwise,$or
returnsfalse
.$or
has the following syntax:For more information on expressions, see Expressions.
Behavior
$or
uses short-circuit logic: the operation stops evaluation after encountering the first true
expression.
In addition to the false
boolean value, $or
evaluates as false
the following: null
, 0
, and undefined
values. The $or
evaluates all other values as true
, including non-zero numeric values and arrays.
Example | Result | |
---|---|---|
{ $or: [ true, false ] } |
true |
|
{ $or: [ [ false ], false ] } |
true |
|
{ $or: [ null, 0, undefined ] } |
false |
|
{ $or: [ ] } |
false |
Example
Consider an inventory
collection with the following documents:
The following operation uses the $or
operator to determine if qty
is greater than 250 or less than 200
:
The operation returns the following results: