[SERVER-46998] Support 'let' variables used within $merge custom pipeline update Created: 19/Mar/20  Updated: 29/Oct/23  Resolved: 18/May/20

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

Type: Task Priority: Major - P3
Reporter: Charlie Swanson Assignee: Katherine Wu (Inactive)
Resolution: Fixed Votes: 0
Labels: qopt-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-46708 Support 'let' variables in update com... Closed
is depended on by DRIVERS-776 Support 'let' option for aggregate c... Closed
Issue split
split from SERVER-46115 Implement 'let' parameters to aggrega... Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 2020-05-18, Query 2020-06-01
Participants:

 Description   

Here we're talking about a $merge stage which uses the pipeline option for 'whenMatched'. If that custom pipeline references a variable defined in the 'let' parameter to the aggregate command, it should work just fine.

Split fromĀ SERVER-46115 since it depends on SERVER-46708 to issue the sub-updates.



 Comments   
Comment by Githook User [ 18/May/20 ]

Author:

{'name': 'Katherine Wu', 'email': 'katherine.wu@mongodb.com', 'username': 'kaywux'}

Message: SERVER-46998 Support 'let' variables used within $merge custom pipeline update
Branch: master
https://github.com/mongodb/mongo/commit/972ce94f18c972b1d648eb89a88f901965fa22dc

Comment by Charlie Swanson [ 03/Apr/20 ]

Correct. All 'let' behaviors will remain unaffected, it will follow the same scoping rules as usual. Same as for $lookup which also has a 'let' option. The innermost definition wins, much like in programming. As a concrete example:

db.runCommand({
  aggregate: "foo",
  pipeline: [{$merge: {into: "target", let: {demo: "INNER"}, whenMatched: [{$set: {value: "$$demo"}}]}}],
  let: {demo: "OUTER"},
})

Will use the value "INNER" inside the 'whenMatched' pipeline. If "$$demo" were used in some other stage, it would take the value "OUTER".

Comment by Asya Kamsky [ 03/Apr/20 ]

$merge supports its own let option - will that remain unchanged?

if so will it mask pipeline level defined let variables?

Generated at Thu Feb 08 05:13:00 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.