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

Allow upserting a document that is missing a shard key field

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.3.1
    • Component/s: Sharding
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL
    • Steps To Reproduce:
      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
    • Sprint:
      Sharding 2019-11-18

      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.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: