[SERVER-9370] Optimize $match $unwind $match sequence in pipeline Created: 17/Apr/13  Updated: 16/Mar/23  Resolved: 20/May/15

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Asya Kamsky Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: optimization
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-17943 add $filter expression to $project to... Closed
Related
related to SERVER-27494 Avoid unwind on multi-key index field... Backlog
Participants:

 Description   

When looking to do aggregations on a subset of documents in arrays, the current "best" practice is to do $match first, then $unwind then $match again.

In other words, if our pipeline is:
{$match:{array.Member:"value"}},{$unwind:"$array"},{$match:{"array.Member":"value"}}

if we can optimize this into something that eliminates unneeded array elements along with unneeded fields this could be reduced to one $match and no $unwind.

redbeard0531 this is what we talked about yesterday, please re-write the description if I didn't capture what we were discussing accurately.



 Comments   
Comment by clemilson barcelos [ 06/May/18 ]

Good evening!
What would be the solution to the case match: {array.Member: "value", {$ unwind: "$ array"}, {$ match: {"array.

Comment by Asya Kamsky [ 08/Apr/15 ]

This is related to request to have $elemMatch or $filter in support of $map so it may become redundant in light of other possible optimizations.

Generated at Thu Feb 08 03:20:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.