- Reference >
- Operators >
- Aggregation Framework Operators >
- Conditional Aggregation Operators >
- $cond (aggregation)
$cond (aggregation)¶
-
$cond
¶ $cond
is a ternary operator that takes an array of three expressions, where the first expression evaluates to a Boolean value. If the first expression evaluates totrue
, then$cond
evaluates and returns the value of the second expression. If the first expression evaluates tofalse
, then$cond
evaluates and returns the third expression.Use the
$cond
operator with the following syntax:All three values in the array specified to
$cond
must be valid MongoDB aggregation expressions or document fields. Do not use JavaScript in any aggregation statements, including$cond
.