Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-44382

Allow upserting a document that is missing a shard key field

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.3.1
    • Affects Version/s: None
    • Component/s: Sharding
    • None
    • Fully Compatible
    • ALL
    • Hide
      // 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
      
      Show
      // 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
    • Sharding 2019-11-18

      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.

            Assignee:
            jack.mulrow@mongodb.com Jack Mulrow
            Reporter:
            jack.mulrow@mongodb.com Jack Mulrow
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: