Binds variables for use in the specified expression, and returns the result of the expression.
$letexpression has the following syntax:
Assignment block for the variables accessible in the
inexpression. To assign a variable, specify a string for the variable name and assign a valid expression for the value.
The variable assignments have no meaning outside the
inexpression, not even within the
The expression to evaluate.
To access variables in aggregation expressions, prefix the variable name with double dollar signs (
$$) and enclosed in quotes. For more information on expressions, see Expressions. For information on use of variables in the aggregation pipeline, see Variables in Aggregation Expressions.
If you modify the values of externally defined variables in the
vars block, the new values take effect only in the
in expression. Outside of the
in expression, the variables retain their previous values.
vars assignment block, the order of the assignment does not matter, and the variable assignments only have meaning inside the
in expression. As such, accessing a variable’s value in the
vars assignment block refers to the value of the variable defined outside the
vars block and not inside the same
For example, consider the following
vars assignment block,
"$$low" refers to the value of an externally defined variable
low and not the variable defined in the same
vars block. If
low is not defined outside this
$let expression block, the expression is invalid.