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