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

error message for upserts without shard key misleading

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 2.6.3
    • Component/s: Sharding, Write Ops
    • Labels:
      None
    • ALL
    • Sharding 2019-04-22, Sharding 2019-05-06, Sharding 2019-05-20, Sharding 2019-06-03

      Upserts require enforcing a uniqueness constraint via a query - in a sharded cluster the only way to do this is if the upsert query is targeted by the shard key. The error message "does not contain shard key", however, is a bit vague in that the shard key may be included in the update expression of the update, but the query also requires it.

      Original description:
      2.6 behavior:

      mongos> sh.shardCollection("test.f1",{a:1})
      { "collectionsharded" : "test.f1", "ok" : 1 }
      mongos> db.f1.update({x:1},{$setOnInsert:{a:1}},{upsert:true})
      WriteResult({
         "nMatched" : 0,
         "nUpserted" : 0,
         "nModified" : 0,
         "writeError" : {
             "code" : 61,
             "errmsg" : "upsert { q: { x: 1.0 }, u: { $setOnInsert: { a: 1.0 } }, multi: false, upsert: true } does not contain shard key for pattern { a: 1.0 }"
         }
      })
      

      2.4 behavior:

      mongos> db.f1.update({x:1},{$setOnInsert:{a:1}},{upsert:true})
      Cannot use commands write mode, degrading to compatibility mode
      WriteResult({
      	"nMatched" : 0,
      	"nUpserted" : 0,
      	"writeError" : {
      		"code" : 13123,
      		"errmsg" : "Can't modify shard key's value. field: a: 1.0 collection: test.f1"
      	}
      })
      

            Assignee:
            janna.golden@mongodb.com Janna Golden
            Reporter:
            alex.komyagin@mongodb.com Alexander Komyagin (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: