On this page本页内容
$ifNull¶Evaluates an expression and returns the value of the expression if the expression evaluates to a non-null value. 计算表达式的值,如果表达式的计算结果为非null值,则返回表达式的值。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:$ifNull表达式语法如下所示:
The arguments can be any valid expression. 参数可以是任何有效的表达式。For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。
The following example use a 以下示例将inventory collection with the following documents:inventory集合与以下文档一起使用:
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:description字段为null或不存在,则以下操作使用$ifNull表达式返回非null的description字段值或字符串"Unspecified":
The operation returns the following results:操作返回以下结果: