Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions source/includes/note-group-pipeline-sort-order.rst

This file was deleted.

9 changes: 4 additions & 5 deletions source/reference/operator/aggregation/first.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ For more information on expressions, see :ref:`aggregation-expressions`.
Behavior
--------

When using :group:`$first` in a :pipeline:`$group` stage, the
:pipeline:`$group` stage should follow a :pipeline:`$sort` stage to
have the input documents in a defined order.

.. include:: /includes/note-group-pipeline-sort-order.rst
When using :group:`$first` in a :pipeline:`$group` stage, the output
value depends on the order of the documents coming into pipeline. To
guarantee a defined order, the :pipeline:`$group` pipeline stage should
follow a :pipeline:`$sort` stage.

Example
-------
Expand Down
9 changes: 4 additions & 5 deletions source/reference/operator/aggregation/last.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,10 @@ For more information on expressions, see :ref:`aggregation-expressions`.
Behavior
--------

When using :group:`$last` in a :pipeline:`$group` stage, the
:pipeline:`$group` stage should follow a :pipeline:`$sort` stage to
have the input documents in a defined order.

.. include:: /includes/note-group-pipeline-sort-order.rst
When using :group:`$last` in a :pipeline:`$group` stage, the output
value depends on the order of the documents coming into pipeline. To
guarantee a defined order, the :pipeline:`$group` pipeline stage should
follow a :pipeline:`$sort` stage.

Example
-------
Expand Down
12 changes: 11 additions & 1 deletion source/reference/operator/aggregation/push.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ Definition

For more information on expressions, see :ref:`aggregation-expressions`.

Behavior
--------

When using :group:`$push` in a :pipeline:`$group` stage, the order of
the documents in the output array is determined by the order of the
documents coming into pipeline. To guarantee a defined order, the
:pipeline:`$group` pipeline stage should follow a :pipeline:`$sort`
stage.

Example
-------

Expand All @@ -52,7 +61,8 @@ compute the list of items and quantities sold for each group:

db.sales.aggregate(
[
{
{ $sort: { date: 1, item: 1 } },
{
$group:
{
_id: { day: { $dayOfYear: "$date"}, year: { $year: "$date" } },
Expand Down