Conditional Operators

Operator

Description

Example

$cond

Takes an array of 3 expressions. If the first expression evaluates to true, the second expression value is returned. Otherwise, the value of the third expression is returned.

{“$cond”: [“c_active”, {“$string”: “active”}, {“$string”: “inactive”}][“c_active”, {“$string”: “active”}, {“$string”: “inactive”}]}

$ifNull

Takes an array of 2 expressions. Returns the value of the first expression unless it evaluates to null, in which case the value of the second expression is returned.

{“$ifNull”: [“c_offset”, {“$integer”: 42}][“c_offset”, {“$integer”: 42}]}