Details
-
New Feature
-
Status: Closed
-
Critical - P2
-
Resolution: Done
-
None
-
Fully Compatible
-
Query 2016-09-19, Query 2016-10-10
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.
Attachments
Issue Links
- is documented by
-
DOCS-9547 Docs for SERVER-19153: Conditionally push $match before $project
-
- Closed
-
- is duplicated by
-
SERVER-23991 $graphLookup should optimize with $match
-
- Closed
-
-
SERVER-4506 aggregation: optimize by pushing matches to earlier in a pipeline
-
- Closed
-
- is related to
-
SERVER-142 Read-only views over collection data.
-
- Closed
-
-
SERVER-26442 Push $sort before $project and $addFields
-
- Open
-
-
SERVER-26598 conditionally push $match before $addFields in aggregation pipeline
-
- Closed
-
- related to
-
SERVER-23991 $graphLookup should optimize with $match
-
- Closed
-