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}}
);
- is related to
-
SERVER-51427 Ensure that find shell helper supports 'let' variables
- Backlog