File tree Expand file tree Collapse file tree 4 files changed +16
-16
lines changed
reference/operator/aggregation Expand file tree Collapse file tree 4 files changed +16
-16
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -32,11 +32,10 @@ Definition
32
32
Behavior
33
33
--------
34
34
35
- When using :group:`$first` in a :pipeline:`$group` stage, the
36
- :pipeline:`$group` stage should follow a :pipeline:`$sort` stage to
37
- have the input documents in a defined order.
38
-
39
- .. include:: /includes/note-group-pipeline-sort-order.rst
35
+ When using :group:`$first` in a :pipeline:`$group` stage, the output
36
+ value depends on the order of the documents coming into pipeline. To
37
+ guarantee a defined order, the :pipeline:`$group` pipeline stage should
38
+ follow a :pipeline:`$sort` stage.
40
39
41
40
Example
42
41
-------
Original file line number Diff line number Diff line change @@ -32,11 +32,10 @@ Definition
32
32
Behavior
33
33
--------
34
34
35
- When using :group:`$last` in a :pipeline:`$group` stage, the
36
- :pipeline:`$group` stage should follow a :pipeline:`$sort` stage to
37
- have the input documents in a defined order.
38
-
39
- .. include:: /includes/note-group-pipeline-sort-order.rst
35
+ When using :group:`$last` in a :pipeline:`$group` stage, the output
36
+ value depends on the order of the documents coming into pipeline. To
37
+ guarantee a defined order, the :pipeline:`$group` pipeline stage should
38
+ follow a :pipeline:`$sort` stage.
40
39
41
40
Example
42
41
-------
Original file line number Diff line number Diff line change @@ -32,6 +32,12 @@ Definition
32
32
Behavior
33
33
--------
34
34
35
+ When using :group:`$push` in a :pipeline:`$group` stage, the order of
36
+ the documents in the output array is determined by the order of the
37
+ documents coming into pipeline. To guarantee a defined order, the
38
+ :pipeline:`$group` pipeline stage should follow a :pipeline:`$sort`
39
+ stage.
40
+
35
41
Memory Restrictions
36
42
~~~~~~~~~~~~~~~~~~~
37
43
@@ -67,7 +73,8 @@ compute the list of items and quantities sold for each group:
67
73
68
74
db.sales.aggregate(
69
75
[
70
- {
76
+ { $sort: { date: 1, item: 1 } },
77
+ {
71
78
$group:
72
79
{
73
80
_id: { day: { $dayOfYear: "$date"}, year: { $year: "$date" } },
You can’t perform that action at this time.
0 commit comments