-
Type: Task
-
Resolution: Fixed
-
Priority: Minor - P4
-
Affects Version/s: 4.1.1
-
Component/s: Sharding
-
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) } } }
- is duplicated by
-
SERVER-42271 Return meaningful error when sharding with a compound hashed index
- Closed