- Reference >
- Operators >
- Aggregation Framework Operators >
- Conditional Aggregation Operators >
- $cond (aggregation)
$cond (aggregation)¶
-
$cond¶ $condis 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$condevaluates and returns the value of the second expression. If the first expression evaluates tofalse, then$condevaluates and returns the third expression.Use the
$condoperator with the following syntax:All three values in the array specified to
$condmust be valid MongoDB aggregation expressions or document fields. Do not use JavaScript in any aggregation statements, including$cond.