Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-51362

Ensure that update and delete shell helpers support 'let' variables

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.9.0
    • Affects Version/s: None
    • Component/s: Write Ops
    • None
    • Fully Compatible
    • Query 2020-10-19

      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}}
      );

            Assignee:
            katherine.wu@mongodb.com Katherine Wu (Inactive)
            Reporter:
            katherine.wu@mongodb.com Katherine Wu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: