Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-12589

The example in "Usage with Options" for shardCollection is incorrect.

    XMLWordPrintableJSON

Details

    Description

      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:

      1. The unique option is missing (see SERVER-37908 for 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.

      2. 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."

      Scope of changes

      Impact to Other Docs

      MVP (Work and Date)

      Resources (Scope or Design Docs, Invision, etc.)

      Attachments

        Activity

          People

            nathan.contino@mongodb.com Nathan Contino (Inactive)
            linda.qin@mongodb.com Linda Qin
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              4 years, 19 weeks, 1 day ago