-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Labels:
Engineering Ticket Description:
I was looking at the optimizing aggregation pipelines docs page and didn't see this one listed.
This is only possible if the subsequent $match doesn't use any computed fields, but there could be a large win with regards to index usage if you could move the $match prior to a $project.
For example:
{ $project: { a: 1, b: 1, newField: { $add: ["$a", "$b"] } } }, { $match: { a : { $gt: 10 } }
is the same as
{ $match: { a : { $gt: 10 } }, { $project: { a: 1, b: 1, newField: { $add: ["$a", "$b"] } } }
because the $match is only using fields that exist in the original document.
- documents
-
SERVER-19153 Conditionally push $match before $project
- Closed
- is related to
-
DOCS-10960 Update Aggregation Pipeline Optimization
- Closed
- related to
-
DOCS-9798 Document that $match can be conditionally pushed before $addFields in an aggregation pipeline
- Closed