Details
-
Task
-
Resolution: Done
-
Major - P3
-
None
-
None
Description
Description
https://docs.mongodb.com/v5.0/reference/command/aggregate/#use-variables-in-let
Let variables only can be used in the aggregation expressions
e.g., you can’t do
db.cakeSales.aggregate(
|
[
|
{ $match: { flavor: "$$flvr" } }
|
],
|
{ let: { flvr: "cherry" } }
|
)
|
it has to be
db.cakeSales.aggregate(
|
[
|
{ $match: {
|
$expr: { $eq: [ "$flavor", "$$flvr" ] },
|
} }
|
],
|
{ let: { flvr: "cherry" } }
|
)
|
In docs it says “To specify variables that can be accessed elsewhere in the command, use the let option.”
Variables also cannot be used in other places like ‘from’ field for $lookup etc.
I think we need to clarify where exactly those work.