To shard the collection, you must open a shell to a mongos instance. The command to shard a collection is sh.shardCollection(). The generic syntax is shown here:
sh.shardCollection(DB.COLLECTION, KEY, UNIQUE, OPTIONS)
The parameters are summarized here:
- DB.COLLECTION (string): This string represents the name of the database and the collection name, separated by a period.
- KEY (JSON document): This parameter is in the form of a JSON key-value pair, where the key is the name of the shard key field and the value is either 1 or hashed. Use hashed if you are using the hashed sharding strategy. If the index is a compound index, the key is the prefix index.
- UNIQUE (Boolean): The default value for this parameter is false. You need to specify true if the index is not hashed and enforces uniqueness. Also, if you plan to add options (see the following bullet), you must set this value to true.
- OPTIONS (JSON document): This parameter is also in the form...