-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Query Optimization
-
Fully Compatible
-
ALL
-
-
QO 2023-06-26, QO 2023-07-10, QO 2023-07-24, QO 2023-08-07, QO 2023-08-21, QO 2023-09-04, QO 2023-09-18, QO 2023-10-02, QO 2023-10-16
In SERVER-48905 we extended the let parameters mechanism so that it works in combination with the $rand expression. For example, the following query was made legal by SERVER-48905:
const findCmd = { find: coll.getName(), projection: {_id: 0, rand: "$$randVal"}, let : {randVal: {$rand: {}}} };
The intended semantics is that the $rand expression is evaluated just once up front and the result is treated as a constant for the remainder of the execution of the query.
In sharded contexts, mongos should generate the random number and pass it to the shards so that all shards see the same random number. This is not working as expected. Glancing at the code, it looks like we are sending the full $rand expression to each shard. As a result, each shard generates its own random number. My script in "steps to reproduce" has a full example of the problem.
- is related to
-
SERVER-82042 Sharded write commands should evaluate 'let' parameter once
- Closed
-
SERVER-48905 Allow $rand in command-level 'let'
- Closed
- related to
-
SERVER-75356 explain command for a find with $expr and let parameters fails if the collection is sharded
- Closed