On this page本页内容
$push
¶Returns an array of all values that result from applying an expression to each document in a group of documents that share the same group by key.返回所有值的数组,这些值是对共享同一组关键字的文档组中的每个文档应用表达式所产生的。
$push
is only available in the 仅在$group
stage.$group
阶段可用。
$push
has the following syntax:语法如下所示:
For more information on expressions, see Expressions.有关表达式的详细信息,请参阅表达式。
Consider a 考虑一个sales
collection with the following documents:sales
集合带有以下文档:
Grouping the documents by the day and the year of the 按照date
field, the following operation uses the $push
accumulator to compute the list of items and quantities sold for each group:date
字段的日期和年份对文档进行分组,下面的操作使用$push
累加器来计算每个组的商品和销售数量列表:
The operation returns the following results:操作返回以下结果: