[SERVER-36524] Add let bounds to $project and $addFields (or new versions thereof) Created: 08/Aug/18  Updated: 06/Dec/22

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

Type: New Feature Priority: Minor - P4
Reporter: Patrick Meredith Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Participants:

 Description   

Currently, there is no way to share a computed expression between different fields of a $project or $addFields other than using a previous $project or $addFields. This proposes adding a let bound to precompute shared expressions. Due to the current syntax of $project and $addFields it seems we will need new pipeline stage names (or perhaps name let and projection $let and $projection?).

{$addFieldsShared: 
   {
    let: {var1: expr1, var2: expr2, ...},
    projection: {field1: expr3, field2: expr4, ...}
   }
}

Where expr3 and expr4 can reference var1 and var2.


Generated at Thu Feb 08 04:43:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.