Skip to content

Commit 69549b7

Browse files
schmallisoSam Kleinman
authored andcommitted
aggregation $sort clarification
- Clarifies that $sort cannot use the index if $group, $unwind, or $project occur before $sort. Signed-off-by: Sam Kleinman <[email protected]>
1 parent 71e5b83 commit 69549b7

File tree

1 file changed

+6
-3
lines changed
  • source/reference/operator/aggregation

1 file changed

+6
-3
lines changed

source/reference/operator/aggregation/sort.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,11 @@ option in :method:`db.collection.aggregate()` method and the
117117

118118
:pipeline:`$sort` operator can take advantage of an index when
119119
placed at the **beginning** of the pipeline or placed **before**
120-
the following aggregation operators: :pipeline:`$project`,
121-
:pipeline:`$unwind`, and :pipeline:`$group`.
122-
120+
the :pipeline:`$project`,
121+
:pipeline:`$unwind`, and :pipeline:`$group` aggregation operators.
122+
If :pipeline:`$project`, :pipeline:`$unwind`, or :pipeline:`$group`
123+
occur prior to the :pipeline:`$sort` operation, :pipeline:`$sort`
124+
cannot use any indexes.
125+
123126
.. todo:: if a sort precedes the first $group in a sharded system,
124127
all documents must go to the mongos for sorting.

0 commit comments

Comments
 (0)