On this page本页内容
$anyElementTrue¶Evaluates an array as a set and returns 将数组作为一个集合求值,如果其中任何元素为true if any of the elements are true and false otherwise. true,则返回true,否则返回false。An empty array returns 空数组返回false.false。
$anyElementTrue 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, 如果集合包含嵌套数组元素,$anyElementTrue does not descend into the nested array but evaluates the array at top-level.$anyElementTrue不会下降到嵌套数组中,而是在顶级对数组求值。
In addition to the 除了布尔值false boolean value, $anyElementTrue evaluates as false the following: null, 0, and undefined values. false外,$anyElementTrue还将以下值计算为false:null、0和undefined值。The $anyElementTrue evaluates all other values as true, including non-zero numeric values and arrays.$anyElementTrue将所有其他值计算为true,包括非零数值和数组。
| Result | ||
|---|---|---|
{ $anyElementTrue: [ [ true, false ] ] } |
true | |
{ $anyElementTrue: [ [ [ false ] ] ] } |
true | |
{ $anyElementTrue: [ [ null, false, 0 ] ] } |
false | |
{ $anyElementTrue: [ [ ] ] } |
false |
Create an example collection named 使用以下文档创建名为survey with the following documents:survey的示例集合:
The following operation uses the 以下操作使用$anyElementTrue operator to determine if the responses array contains any value that evaluates to true:$anyElementTrue运算符来确定responses数组是否包含任何计算结果为true的值:
The operation returns the following results:操作返回以下结果: