[SERVER-36445] shardCollection command needs a better error message when specifying more than one hashed shard key Created: 03/Aug/18  Updated: 29/Oct/23  Resolved: 06/Dec/18

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 4.1.1
Fix Version/s: 4.1.7

Type: Task Priority: Minor - P4
Reporter: Kyle Suarez Assignee: Kim Tao
Resolution: Fixed Votes: 0
Labels: ShardingRoughEdges, neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-42271 Return meaningful error when sharding... Closed
Backwards Compatibility: Fully Compatible
Sprint: Sharding 2018-12-17
Participants:

 Description   

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



 Comments   
Comment by Githook User [ 06/Dec/18 ]

Author:

{'name': 'Kim Tao', 'email': 'kimberly.tao@10gen.com'}

Message: SERVER-36445: change error message when specifying more than 1 hashed field on a shard key
Branch: master
https://github.com/mongodb/mongo/commit/f741ed661bcf4b29da3d3a8fb833e9017e653e6e

Generated at Thu Feb 08 04:43:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.