Skip to content

Commit be47eb1

Browse files
DOCSP-27261 Add guidance for $project stage placement (#2322)
* first draft * edits * review feedback * wording * add link to project page * typo fix * add clarity * wording * wording * add advice to project page
1 parent 661c894 commit be47eb1

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
@@ -36,6 +36,13 @@ the fields in the documents to obtain the results. If so, the pipeline
3636
only uses those fields, reducing the amount of data passing through the
3737
pipeline.
3838

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

4148
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)