-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Labels:
-
0.1
Description
https://docs.mongodb.com/manual/reference/method/sh.shardCollection/index.html#usage-with-options
The example is as below:
sh.shardCollection( "phonebook.contacts", { last_name: "hashed" }, { numInitialChunks: 5, collation: { locale: "pt" } } )
There are two issues:
- The unique option is missing (see
SERVER-37908for more details). This command will fail with:{ "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(1554158728, 4), "$clusterTime" : { "clusterTime" : Timestamp(1554158728, 4), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }
Since the shard key is hashed shard key, unique should be false here.
- Non-simple collations are not permitted on the shard key (see
SERVER-24751). However a collation of pt for Portuguese is used in this example. The command would fail with:{ "ok" : 0, "errmsg" : "The collation for shardCollection must be {locale: 'simple'}, but found: { locale: \"pt\" }", "code" : 2, "codeName" : "BadValue", "operationTime" : Timestamp(1554159087, 5), "$clusterTime" : { "clusterTime" : Timestamp(1554159087, 5), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }
As such, the command should be:
sh.shardCollection( "phonebook.contacts", { last_name: "hashed" }, false, { numInitialChunks: 5, collation: { locale: "simple" } } )
Also, the sentence above "a collation of pt for Portuguese." should be changed to "a collation of simple."