- Reference >
- Operators >
- Aggregation Pipeline Operators >
- $ifNull (aggregation)
$ifNull (aggregation)¶
On this page
Definition¶
-
$ifNull
¶ Evaluates an expression and returns the value of the expression if the expression evaluates to a non-null value. If the expression evaluates to a null value, including instances of undefined values or missing fields, returns the value of the replacement expression.
The
$ifNull
expression has the following syntax:The arguments can be any valid expression. For more information on expressions, see Expressions.
Example¶
The following example use a inventory
collection with the following
documents:
The following operation uses the $ifNull
expression to
return either the non-null description
field value or the string
"Unspecified"
if the description
field is null or does not
exist:
The operation returns the following results: