Currently, command-level 'let' only accepts expressions that optimize to a constant. We'd like to allow $rand in a command-level 'let': it would pick a random value once up front, and the bound variable would be constant throughout the query. We can make this work by calling evaluate() instead of optimize().
But we should still report an error when the expression tries to refer to any field (as opposed to returning missing). We can use DepsTracker to uassert when the command-level-let-bound expressions have any unmet dependencies (fields, variables, or metadata).
- is related to
-
SERVER-82042 Sharded write commands should evaluate 'let' parameter once
- Closed
- related to
-
SERVER-75927 Shards see different values for 'let' parameter when using $rand
- Closed