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

shardCollection command needs a better error message when specifying more than one hashed shard key

    • Fully Compatible
    • Sharding 2018-12-17

      You're only allowed a hashed shard key on one field. But if you try to create a hashed shard key on more than one field, you get a confusing error message:

      mongos> sh.shardCollection("test.sharded", {_id: "hashed", shardKey: "hashed"})
      {
              "ok" : 0,
              "errmsg" : "Field _id can only be 1 or 'hashed'",
              "code" : 2,
              "codeName" : "BadValue",
              "operationTime" : Timestamp(1533326357, 1),
              "$clusterTime" : {
                      "clusterTime" : Timestamp(1533326357, 1),
                      "signature" : {
                              "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                              "keyId" : NumberLong(0)
                      }
              }
      }
      

      Looks like it always complains about the first field:

      mongos> sh.shardCollection("test.sharded", {shardKey: "hashed", _id: "hashed"})
      {
              "ok" : 0,
              "errmsg" : "Field shardKey can only be 1 or 'hashed'",
              "code" : 2,
              "codeName" : "BadValue",
              "operationTime" : Timestamp(1533326476, 4),
              "$clusterTime" : {
                      "clusterTime" : Timestamp(1533326476, 4),
                      "signature" : {
                              "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                              "keyId" : NumberLong(0)
                      }
              }
      }
      

            Assignee:
            kimberly.tao@mongodb.com Kim Tao
            Reporter:
            kyle.suarez@mongodb.com Kyle Suarez
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: