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

Sharded upsert incorrectly errors if _id shard key not in replace spec

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.6.0-rc0
    • Component/s: Sharding, Write Ops
    • Labels:
    • Sharding
    • ALL

      If there is no _id in the replace spec it is copied from the query. Note that non-upsert updates handle this correctly:

      > sh.shardCollection('test.sharded', {_id:1})
      { "collectionsharded" : "test.sharded", "ok" : 1 }
      > db.sharded.runCommand('update', {updates:[{q:{_id:1}, u:{}, upsert: true}]})
      {
              "ok" : 1,
              "nModified" : 0,
              "n" : 0,
              "writeErrors" : [
                      {
                              "index" : 0,
                              "code" : 61,
                              "errmsg" : "upsert { q: { _id: 1.0 }, u: {}, upsert: true } does not contain shard key for pattern { _id: 1.0 }"
                      }
              ]
      }
      > db.sharded.runCommand('update', {updates:[{q:{_id:1}, u:{}, upsert: false}]})
      { "ok" : 1, "nModified" : 0, "n" : 0 }
      

      This should only be allowed if sharded on _id, because replace-style updates preserve _id.

            Assignee:
            backlog-server-sharding [DO NOT USE] Backlog - Sharding Team
            Reporter:
            mathias@mongodb.com Mathias Stearn
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: