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

Sharding a collection with invalid options displays a misleading error

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.6.8, 4.0.3
    • Component/s: Sharding
    • Labels:
      None
    • Sharding
    • ALL
    • Hide
      1. Launch a sharded cluster
      2.  sh.enableSharding("test") 
      3.  sh.shardCollection("test.foo", {_id:"hashed"}, {pieinthesky:1}) 
      4. Error appears that is not indicative of the true problem
      Show
      Launch a sharded cluster sh.enableSharding( "test" ) sh.shardCollection( "test.foo" , {_id: "hashed" }, {pieinthesky:1}) Error appears that is not indicative of the true problem

      When sharding a collection with a hashed shard key but including invalid options will output the following error:

      mongos> sh.shardCollection("test.foo", {_id:"hashed"}, {pieinthesky:1})
      {
      	"ok" : 0,
      	"errmsg" : "Hashed shard keys cannot be declared unique. It's possible to ensure uniqueness on the hashed field by declaring an additional (non-hashed) unique index on the field.",
      	"code" : 72,
      	"codeName" : "InvalidOptions",
      	"operationTime" : Timestamp(1541185291, 4),
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1541185291, 4),
      		"signature" : {
      			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      			"keyId" : NumberLong(0)
      		}
      	}
      }
      

      The problem is my invalid option, not the hashed shard key.

            Assignee:
            backlog-server-sharding [DO NOT USE] Backlog - Sharding Team
            Reporter:
            daniel.hatcher@mongodb.com Danny Hatcher (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: