[SERVER-82042] Sharded write commands should evaluate 'let' parameter once Created: 10/Oct/23  Updated: 18/Dec/23  Resolved: 18/Dec/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.3.0-rc0

Type: Bug Priority: Major - P3
Reporter: David Percy Assignee: Mihai Andrei
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-75927 Shards see different values for 'let'... Closed
related to SERVER-48905 Allow $rand in command-level 'let' Closed
Assigned Teams:
Query Execution
Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: QE 2023-11-27, QE 2023-12-11, QE 2023-12-25
Participants:

 Description   

Write commands that take 'let' parameters should ensure those expressions are evaluated once, instead of once per shard. For example, in a multi-update you should be able to use {let: {r: {$rand: {}}}} to pick a single random value and use it consistently when updating each document.

SERVER-75927 fixes this for the 'find' command.



 Comments   
Comment by Githook User [ 15/Dec/23 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@mongodb.com', 'username': 'mtandrei'}

Message: SERVER-82042 Evaluate let parameters on sharded write commands once

GitOrigin-RevId: 079ea6535731dc275ef4cda11586a8751619962c
Branch: master
https://github.com/mongodb/mongo/commit/8c2b283502241fd1c4502d107ab1fd07cdbede62

Comment by Githook User [ 10/Oct/23 ]

Author:

{'name': 'David Percy', 'email': 'david.percy@mongodb.com', 'username': 'dpercy'}

Message: SERVER-75927 Evaluate command-level let only once, even when sharded

Command-level let bindings are evaluated once for the whole command. For
most expressions this is not observable, but for $rand it is. If you
need a random value drawn once and then used consistently within the
query, you use a command-level binding.

Previously this was only working correctly for sharded aggregate queries:
we were evaluating the let bindings on each shard separately. This commit
fixes the find command: it ensures we evaluate the expressions once on
mongos and then serialize the resulting values to the shards.

This commit also includes test cases to demonstrate the same bug in
write commands, to be fixed separately (SERVER-82042).
Branch: master
https://github.com/mongodb/mongo/commit/7533908c28d85da5356b2b9c49ff29d026cda2f1

Generated at Thu Feb 08 06:48:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.