|
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.
|