From d450986084b06a310c4d7182ef33d9fd80ebe255 Mon Sep 17 00:00:00 2001 From: Allison Moore Date: Thu, 15 Jan 2015 10:45:25 -0500 Subject: [PATCH] aggregation $sort clarification - Clarifies that $sort cannot use the index if $group, $unwind, or $project occur before $sort. --- source/reference/operator/aggregation/sort.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/source/reference/operator/aggregation/sort.txt b/source/reference/operator/aggregation/sort.txt index ba0cdcd72e5..bcf983a8b8c 100644 --- a/source/reference/operator/aggregation/sort.txt +++ b/source/reference/operator/aggregation/sort.txt @@ -117,8 +117,11 @@ option in :method:`db.collection.aggregate()` method and the :pipeline:`$sort` operator can take advantage of an index when placed at the **beginning** of the pipeline or placed **before** -the following aggregation operators: :pipeline:`$project`, -:pipeline:`$unwind`, and :pipeline:`$group`. - +the :pipeline:`$project`, +:pipeline:`$unwind`, and :pipeline:`$group` aggregation operators. +If :pipeline:`$project`, :pipeline:`$unwind`, or :pipeline:`$group` +occur prior to the :pipeline:`$sort` operation, :pipeline:`$sort` +cannot use any indexes. + .. todo:: if a sort precedes the first $group in a sharded system, all documents must go to the mongos for sorting.