-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
MongoDB's API supports passing in User-defined variables in the let parameter for some functions (listed below) but Mongo Playground doesn't support it. The error is:
fail to run update: write exception: write errors: [Invalid $set :: caused by :: Use of undefined variable: newFlavor]
However, using let in these commands in Mongo Compass Compass-shell works:
- find
- db.collection.update
- update
- updateMany supports it too but it's not documented
- aggregate
Is it due to let not being supported in Mongoose options?
Repro example from the docs, executed in Compass-shell:
Initialise:
db.cakeFlavors.insertMany( [
{ _id: 1, flavor: "chocolate" },
{ _id: 2, flavor: "strawberry" },
{ _id: 3, flavor: "cherry" }
] )Using update with let params:
db.cakeFlavors.update(
{ $expr: { $eq: [ "$flavor", "$$targetFlavor" ] } },
[ { $set: { flavor: "$$newFlavor" } } ],
{ let : { targetFlavor: "cherry", newFlavor: "orange" }, multi: true }
)
// result
{
acknowledged: true, insertedId: null, matchedCount: 1, modifiedCount: 1, upsertedCount: 0
}Or using updateMany with let params:
db.cakeFlavors.updateMany(
{ $expr: { $eq: [ "$flavor", "$$targetFlavor" ] } },
[ { $set: { flavor: "$$newFlavor" } } ],
{ let : { targetFlavor: "cherry", newFlavor: "orange" } }
)Metadata
Metadata
Assignees
Labels
No labels