- Reference >
- Operators >
- Aggregation Framework Operators >
- Group Aggregation Operators >
- $push (aggregation)
$push (aggregation)¶
On this page
-
$push¶ Returns an array of all the values found in the selected field among the documents in that group. A value may appear more than once in the result set if more than one field in the grouped documents has that value.
Example¶
The following examples use the following collection named users as
the input for the aggregation pipeline:
Push Values of a Single Field Into the Returned Array Field¶
To group by age and return all the user values for each age, use the
$push operator.
For each age, the operation returns the field users that
contains an array of all the user values associated with that age:
Push Documents Into the Returned Array Field¶
The $push operator can return an array of documents.
To group by age and return all the user and associated
score values for each age, use the $push operator.
For each age, the operation returns the field users that
contains an array of documents. These documents contain the fields
userid and score that hold respectively the user value and
the score value associated with that age: