The find command supports let parameters, but the db.collection.find() shell helper does not.
Also, see this JIRA:
https://jira.mongodb.org/browse/SERVER-51362
The following test works:
db.cakeFlavors.drop()
db.cakeFlavors.insert( [
{ _id: 1, flavor: "chocolate" },
{ _id: 2, flavor: "strawberry" },
{ _id: 3, flavor: "cherry" }
] )
db.cakeFlavors.runCommand( {
find: db.cakeFlavors.getName(),
let : { targetFlavor: "chocolate" },
filter: { $expr: { $eq: [ "$flavor", "$$targetFlavor" ] } },
} )
But the corresponding command using the shell helper fails. I'm not 100% sure I'm executing it properly, as there is no test case for it.
db.cakeFlavors.find(
{ "$flavor": { "$$targetFlavor" } },
{ let: { targetFlavor: "chocolate" } }
)
I also tried this, which also generated an error:
db.cakeFlavors.find(
{ "$flavor": { "$$targetFlavor" } },
let: { targetFlavor: "chocolate" }
)
- related to
-
SERVER-51362 Ensure that update and delete shell helpers support 'let' variables
-
- Closed
-