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

error message for upserts without shard key misleading

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Gone away
    • Affects Version/s: 2.6.3
    • Fix Version/s: None
    • Component/s: Sharding, Write Ops
    • Labels:
      None
    • Operating System:
      ALL
    • Sprint:
      Sharding 2019-04-22, Sharding 2019-05-06, Sharding 2019-05-20, Sharding 2019-06-03

      Description

      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"
      	}
      })
      

        Attachments

          Activity

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: