On this page本页内容
$slice
¶New in version 3.2.版本3.2中的新功能。
Returns a subset of an array.返回数组的子集。
$slice
has one of two syntax forms:$slice
有两种语法形式之一:
The following syntax returns elements from either the start or end of the array:以下语法返回数组开头或结尾的元素:
The following syntax returns elements from the specified position in the array:以下语法返回数组中指定位置的元素:
<array> |
|
<position> |
|
<n> |
|
For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。
A collection named 名为users
contains the following documents:users
的集合包含以下文档:
The following example returns at most the first three elements in the 以下示例最多为每个用户返回favorites
array for each user:favorites
数组中的前三个元素:
The operation returns the following results:操作返回以下结果: