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

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

    XMLWordPrintableJSON

Details

    • Task
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 4.9.0
    • Write Ops
    • None
    • Fully Compatible
    • Query 2020-10-19

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

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: