[SERVER-44382] Allow upserting a document that is missing a shard key field Created: 01/Nov/19  Updated: 29/Oct/23  Resolved: 06/Nov/19

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 4.3.1

Type: Bug Priority: Major - P3
Reporter: Jack Mulrow Assignee: Jack Mulrow
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Documented
is documented by DOCS-13205 Investigate changes in SERVER-44382: ... Closed
Related
is related to SERVER-42390 Allow documents in a sharded collecti... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

// Assuming foo.bar is a sharded collection with shard key "skey"
const sessionColl = db.getMongo().startSession({retryWrite: true}).getDatabase("foo");
sessionColl.bar.update({skey: 10}, {a: 1}, {upsert: true}); // Fails with NoSuchKey

Sprint: Sharding 2019-11-18
Participants:

 Description   

SERVER-42390 allowed users to insert documents that are missing shard key fields and unset shard key fields through an update. An upsert that doesn't match an existing document takes a different code path than other updates, which currently incorrectly will reject a write that would result in a document without a shard key field because of this check. Instead, the upsert path should only assert the shard key paths do not contain arrays and that _id is present and does not contain an array.

Note that mongos will still require an upsert to have all shard key fields. This ticket allows upserts where the query portion has the full shard key but the update causes the document to end up missing shard key fields to succeed. Two ways this can happen are if theĀ replacement doc is missing shard key fields or the update unsets shard key fields.



 Comments   
Comment by Githook User [ 06/Nov/19 ]

Author:

{'name': 'Jack Mulrow', 'username': 'jsmulrow', 'email': 'jack.mulrow@mongodb.com'}

Message: SERVER-44382 Allow upserting documents with missing shard key fields
Branch: master
https://github.com/mongodb/mongo/commit/4271acb624b7654afd9a7c81efaf884a5a30642a

Generated at Thu Feb 08 05:05:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.