[DOCS-9547] Docs for SERVER-19153: Conditionally push $match before $project Created: 05/Dec/16  Updated: 27/Oct/17  Resolved: 24/Oct/17

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Emily Hall Assignee: Nicholas Larew
Resolution: Done Votes: 0
Labels: bi-performance, optimization
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-19153 Conditionally push $match before $pro... Closed
Related
related to DOCS-9798 Document that $match can be condition... Closed
is related to DOCS-10960 Update Aggregation Pipeline Optimization Closed
Participants:
Days since reply: 6 years, 16 weeks, 1 day ago

 Description   

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.



 Comments   
Comment by Kyle Suarez [ 24/Oct/17 ]

Thanks, nick.larew!

Comment by Nicholas Larew [ 24/Oct/17 ]

Hi Kyle,

There is a PR on the docs repo for this ticket and DOCS-9798.
https://github.com/mongodb/docs/pull/3049

Comment by Kyle Suarez [ 24/Oct/17 ]

Is there a docs commit with the changes?

Generated at Thu Feb 08 07:58:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.