Skip to content

Commit a38fdc1

Browse files
(v5.0) DOCSP-27261 Add guidance for $project stage placement (#2322) (#2563)
* first draft * edits * review feedback * wording * add link to project page * typo fix * add clarity * wording * wording * add advice to project page
1 parent 155db23 commit a38fdc1

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

source/core/aggregation-pipeline-optimization.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ the fields in the documents to obtain the results. If so, the pipeline
3737
will only use those required fields, reducing the amount of data
3838
passing through the pipeline.
3939

40+
``$project`` Stage Placement
41+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42+
43+
.. |$project| replace:: :pipeline:`$project`
44+
45+
.. include:: /includes/aggregation/fact-project-stage-placement.rst
46+
4047
.. _aggregation-pipeline-sequence-optimization:
4148

4249
Pipeline Sequence Optimization
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
When you use a |$project| stage it should typically be the last stage in
2+
your pipeline, used to specify which fields to return to the client.
3+
4+
Using a ``$project`` stage at the beginning or middle of a pipeline to
5+
reduce the number of fields passed to subsequent pipeline stages is
6+
unlikely to improve performance, as the database performs this
7+
optimization automatically.

source/reference/operator/aggregation/project.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,13 @@ fails with the same error:
205205

206206
{ $project: { "contact.address.country": 1, contact: 1 } }
207207

208+
``$project`` Stage Placement
209+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
210+
211+
.. |$project| replace:: ``$project``
212+
213+
.. include:: /includes/aggregation/fact-project-stage-placement.rst
214+
208215
Restrictions
209216
~~~~~~~~~~~~
210217

0 commit comments

Comments
 (0)