The evaluate() method of ExpressionIfNull short circuits when it finds the first non-nullish value. So an expression like {$ifNull: [null, "$a"]} could be optimized to "$a".
Currently it doesn't override optimize(). It inherits some optimizations from ExpressionNary, but short circuiting is not one of them.
- causes
-
SERVER-58680 $ifNull behaves differently in latest
- Closed
- is related to
-
SERVER-55297 Short circuit $cond if condition is a constant
- Closed