On this page本页内容
$allElementsTrue¶Evaluates an array as a set and returns 将数组作为集合计算,如果数组中没有元素为true if no element in the array is false. false,则返回true。Otherwise, returns 否则,返回false. An empty array returns true.false。空数组返回true。
$allElementsTrue has the following syntax:语法如下所示:
The <expression> itself must resolve to an array, separate from the outer array that denotes the argument list. <expression>本身必须解析为一个数组,与表示参数列表的外部数组分开。For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。
If a set contains a nested array element, 如果集合包含嵌套数组元素,$allElementsTrue does not descend into the nested array but evaluates the array at top-level.$allElementsTrue不会下降到嵌套数组中,而是在顶级对数组求值。
In addition to the 除false boolean value, $allElementsTrue evaluates as false the following: null, 0, and undefined values. false布尔值外,$allElementsTrue还将以下值计算为假:null、0和undefined的值。The $allElementsTrue evaluates all other values as true, including non-zero numeric values and arrays.$AllegerementStrue将所有其他值计算为true,包括非零数值和数组。
| Result | ||
|---|---|---|
{ $allElementsTrue: [ [ true, 1, "someString" ] ] } |
true | |
{ $allElementsTrue: [ [ [ false ] ] ] } |
true | |
{ $allElementsTrue: [ [ ] ] } |
true | |
{ $allElementsTrue: [ [ null, false, 0 ] ] } |
false |
Create an example collection named 使用以下文档创建名为survey with the following documents:survey的示例集合:
The following operation uses the 以下操作使用$allElementsTrue operator to determine if the responses array only contains values that evaluate to true:$allElementsTrue运算符来确定responses数组是否只包含计算结果为true的值:
The operation returns the following results:操作返回以下结果: