[SERVER-51362] Ensure that update and delete shell helpers support 'let' variables Created: 05/Oct/20  Updated: 29/Oct/23  Resolved: 09/Oct/20

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: None
Fix Version/s: 4.9.0

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

Issue Links:
Documented
is documented by DOCS-13923 Investigate changes in SERVER-51362: ... Closed
Related
is related to SERVER-51427 Ensure that find shell helper support... Backlog
Backwards Compatibility: Fully Compatible
Sprint: Query 2020-10-19
Participants:

 Description   

The update command supports let parameters, but the db.collection.update() shell helper does not.

 

The following update command works:

db.runCommand({
    update: db.cakeSales.getName(),
    updates: [
        {q: {$expr: {$eq: [“$salesTotal”, “$$targetTotal”], u: [{$set: {salesTotal: “$$newTotal”}}]}
    ],
    let : {targetTotal: 2150, newTotal: 2155}
});

 

But the corresponding command using the shell helper fails with errmsg: “Use of undefined variable: targetTotal”.

db.cakeSales.update(
   {$expr: {$eq: [“$salesTotal”, “$$targetTotal”],
   {$set: {salesTotal: “$$newTotal”,
   {let : {targetTotal: 4350, newTotal: 4200}}
);



 Comments   
Comment by Jason Price [ 12/Oct/20 ]

After a conversation with katherine.wu on Slack, Katherine mentioned that the helper method to get the "let" option will be db.collection.remove(), not the delete helper methods.

So, the helper methods to get the "let" option as part of this JIRA are:
db.collection.update()
db.collection.remove()

The doc JIRA is:
https://jira.mongodb.org/browse/DOCS-13620

Comment by Githook User [ 08/Oct/20 ]

Author:

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

Message: SERVER-51362 Ensure update and delete shell helpers support 'let' variables
Branch: master
https://github.com/mongodb/mongo/commit/d51e73db78ed0e93ca2b88bc293fc218c521ae06

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