You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During the ``$match`` stage, the server can use an index if ``$match`` is the first stage in the pipeline, after any optimizations from the :ref:`query planner <query-plans-query-optimization>`.
518
515
519
-
``$sort`` stage
520
-
:pipeline:`$sort` can benefit from an index as long as it is not
521
-
preceded by a :pipeline:`$project`, :pipeline:`$unwind`, or
516
+
:pipeline:`$sort` stage
517
+
During the ``$sort`` stage, the server can use an index if the stage is not preceded by a :pipeline:`$project`, :pipeline:`$unwind`, or
522
518
:pipeline:`$group` stage.
523
519
524
-
``$group`` stage
525
-
:pipeline:`$group` can use an index to find the first document in
526
-
each group if it meets all of the following conditions:
527
-
528
-
- a :pipeline:`$sort` stage sorts the grouping field before
529
-
:pipeline:`$group`
520
+
:pipeline:`$group` stage
521
+
During the ``$group`` stage, the server can use an index to quickly
522
+
find the :group:`$first <$first>` or :group:`$last <$last>` document
523
+
in each group if the stage meets both of these conditions:
530
524
531
-
- an index exists that matches the sort order on the grouped field
525
+
- The pipeline :pipeline:`sorts <$sort>` and :pipeline:`groups
526
+
<$group>` by the same field.
532
527
533
-
- :group:`$first` is the only accumulator in the :pipeline:`$group`
534
-
stage
528
+
- The ``$group`` stage only uses the :group:`$first` or
529
+
:group:`$last` accumulator operator.
535
530
536
-
See :ref:`$group Performance Optimizations <group-pipeline-optimization>`
537
-
for an example.
531
+
See :ref:`$group Performance Optimizations <group-pipeline-optimization>` for an example.
538
532
539
-
``$geoNear`` stage
540
-
:pipeline:`$geoNear` always uses an index, since it must be the first
541
-
stage in a pipeline and requires a :ref:`geospatial index <index-feature-geospatial>`.
533
+
:pipeline:`$geoNear` stage
534
+
The server always uses an index for the ``$geoNear`` stage, since it
535
+
requires a :ref:`geospatial index <index-feature-geospatial>`.
542
536
543
537
Additionally, stages later in the pipeline that retrieve data from
544
538
other, unmodified collections can use indexes on those collections
0 commit comments