...
The check for whether the shard key is being modified in a multi=true update happens after the check for whether the shard owns the document being updated has said it's fine to proceed with the update. We should instead disallow any attempts to change the shard key in multi=true updates. // If the shard key fields remain unchanged by this update or if this document is an orphan and // so does not belong to this shard, we can skip the rest of the checks. if ((newShardKey.woCompare(oldShardKey) == 0) || !metadata->keyBelongsToMe(oldShardKey)) { return false; } ... // We do not allow updates to the shard key when 'multi' is true. uassert(ErrorCodes::InvalidOptions, "Multi-update operations are not allowed when updating the shard key field.", !_params.request->isMulti());
xgen-internal-githook commented on Fri, 4 Jun 2021 15:58:08 +0000: Author: {'name': 'Haley Connelly', 'email': 'haley.connelly@mongodb.com', 'username': 'haleyConnelly'} Message: SERVER-46811 multi=true updates can modify the shard key of orphan documents and cause them to become owned (cherry picked from commit 17e468583ec1a7e9755b34b50eaa7cf017a1c96e) Branch: v4.2 https://github.com/mongodb/mongo/commit/b9cd445b93ec8fb8c960afef41cc31f2ac47eba7 xgen-internal-githook commented on Wed, 12 Aug 2020 00:04:47 +0000: Author: {'name': 'Haley Connelly', 'email': 'haley.connelly@mongodb.com', 'username': 'haleyConnelly'} Message: SERVER-46811 multi=true updates can modify the shard key of orphan documents and cause them to become owned (cherry picked from commit 17e468583ec1a7e9755b34b50eaa7cf017a1c96e) Branch: v4.4 https://github.com/mongodb/mongo/commit/3a20a63dc5e96948131dc0393c07a644f49e8109 xgen-internal-githook commented on Tue, 14 Jul 2020 17:15:59 +0000: Author: {'name': 'Haley Connelly', 'email': 'haley.connelly@mongodb.com', 'username': 'haleyConnelly'} Message: SERVER-46811 multi=true updates can modify the shard key of orphan documents and cause them to become owned Branch: master https://github.com/mongodb/mongo/commit/17e468583ec1a7e9755b34b50eaa7cf017a1c96e haley.connelly commented on Mon, 29 Jun 2020 19:27:42 +0000: Just as an update: The behavior in master has changed since Max posted the repro. It now fails here [js_test:repro_update_orphan_shard_key] 2020-06-29T19:15:37.247+0000 uncaught exception: Error: write failed with error: { [js_test:repro_update_orphan_shard_key] 2020-06-29T19:15:37.247+0000 "nMatched" : 0, [js_test:repro_update_orphan_shard_key] 2020-06-29T19:15:37.247+0000 "nUpserted" : 0, [js_test:repro_update_orphan_shard_key] 2020-06-29T19:15:37.247+0000 "nModified" : 0, [js_test:repro_update_orphan_shard_key] 2020-06-29T19:15:37.247+0000 "writeError" : { [js_test:repro_update_orphan_shard_key] 2020-06-29T19:15:37.247+0000 "code" : 31025, [js_test:repro_update_orphan_shard_key] 2020-06-29T19:15:37.248+0000 "errmsg" : "Shard key update is not allowed without specifying the full shard key in the query" [js_test:repro_update_orphan_shard_key] 2020-06-29T19:15:37.248+0000 } [js_test:repro_update_orphan_shard_key] 2020-06-29T19:15:37.248+0000 } : It fails with this right before it has the change to assert "Multi-update operations are not allowed when updating the shard key field".
Click on a version to see all relevant bugs
MongoDB Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.