[DOCS-12589] The example in "Usage with Options" for shardCollection is incorrect. Created: 01/Apr/19  Updated: 30/Oct/23  Resolved: 01/Oct/19

Status: Closed
Project: Documentation
Component/s: manual, Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Bug Priority: Major - P3
Reporter: Linda Qin Assignee: Nathan Contino (Inactive)
Resolution: Fixed Votes: 1
Labels: docs-onboarding-candidate
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 4 years, 19 weeks, 1 day ago
Epic Link: DOCSP-1769
Story Points: 0.1

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



 Comments   
Comment by Githook User [ 01/Oct/19 ]

Author:

{'username': 'nathan-contino-mongo', 'email': 'nathan.contino@mongodb.com', 'name': 'nathan-contino-mongo'}

Message: DOCS-12589: shard collation options example fix
Branch: v3.4
https://github.com/mongodb/docs/commit/c5a3de1153d733b2ccbc550b34b6be5ad68483dc

Comment by Githook User [ 01/Oct/19 ]

Author:

{'username': 'nathan-contino-mongo', 'email': 'nathan.contino@mongodb.com', 'name': 'nathan-contino-mongo'}

Message: DOCS-12589: shard collation options example fix
Branch: v3.6
https://github.com/mongodb/docs/commit/105e440b0d682e35e0d147877e8404bd710c72f9

Comment by Githook User [ 01/Oct/19 ]

Author:

{'name': 'nathan-contino-mongo', 'username': 'nathan-contino-mongo', 'email': 'nathan.contino@mongodb.com'}

Message: DOCS-12589: shard collation options example fix
Branch: v4.0
https://github.com/mongodb/docs/commit/f38a15937a86684cb056634de3822708aa11a6f9

Comment by Githook User [ 27/Sep/19 ]

Author:

{'username': 'nathan-contino-mongo', 'email': 'nathan.contino@mongodb.com', 'name': 'nathan-contino-mongo'}

Message: DOCS-12589: shard collation options example fix
Branch: master
https://github.com/mongodb/docs/commit/7ed30b3df48a85d3c88d8661519a4553716279f7

Generated at Thu Feb 08 08:05:37 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.