On this page本页内容
$reverseArray
¶New in version 3.4.版本3.4中的新功能。
Accepts an array expression as an argument and returns an array with the elements in reverse order.接受数组表达式作为参数,并返回元素顺序相反的数组。
$reverseArray
has the following operator expression syntax:具有以下运算符表达式语法:
The argument can be any valid expression as long as it resolves to an array.参数可以是任何有效的表达式,只要它解析为数组。
If the argument resolves to a value of 如果参数解析为null
or refers to a missing field, $reverseArray
returns null
.null
值或引用缺少的字段,$reverseArray
返回null
。
If the argument does not resolve to an array or 如果参数未解析为数组或null
nor refers to a missing field, $reverseArray
returns an error.null
,也未引用缺少的字段,$reverseArray
将返回错误。
参数为空数组时,$reverseArray
returns an empty array when the argument is an empty array.$reverseArray
返回空数组。
If the argument contains subarrays, 如果参数包含子数组,$reverseArray
only operates on the top level array elements and will not reverse the contents of subarrays.$reverseArray
只对顶级数组元素起作用,不会反转子数组的内容。
[ 3, 2, 1 ] | |
[ "baz", "bar" ] | |
null | |
[ ] | |
[ [ 4, 5, 6 ], [ 1, 2, 3 ] ] |
[1] | $literal expression or keep the outer array that designates the argument list (e.g. [ [ 1, 2, 3 ]
] ) to pass in the literal array [1, 2, 3] .$literal 表达式中,或者保留指定参数列表的外部数组(例如[[1,2,3]] )以传入文字数组[1,2,3] 。 |
A collection named 名为users
contains the following documents:users
的集合包含以下文档:
The following example returns an array containing the elements of the 以下示例返回一个数组,该数组包含favorites
array in reverse order:favorites
数组的元素,顺序与此相反:
The operation returns the following results:操作返回以下结果: