-
Type: Improvement
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
In general, aggregation pipelines are automatically optimized by the server to include only the data which is to be used in the pipeline and/or output at the end. Adding a $project in earlier stages doesn't really limit the amount of data being used in the stages that follow, because the pipeline dependency analysis automatically figures out which fields are needed by the pipeline. Adding $project stages in mid-pipeline can therefore be redundant, and it can prevent pipeline dependency analysis from figuring out which fields are needed by the pipeline (which it does automatically).
The $project is typically intended only to rename fields or reshape data to be output, and therefore, in most cases, $project should only be placed at the end of an aggregation pipeline and can be avoided in many cases.
This is an enhancement request for optimizing mid-pipeline $project stages, and possibly convert them to $addFields, so that they don't interfere with the pipeline dependency analysis.
- duplicates
-
SERVER-13703 Presence of extraneous $project causes a less efficient plan to be used
- Backlog