MongoDB Documentation, Release 3.0.4 You can instead use the addShard database command, which lets you specify a name and maximum size for the shard. If you do not specify these, MongoDB automatically assigns a name and maximum size. To use the database command, see addShard . The following are examples of adding a shard with sh.addShard() : • To add a shard for a replica set named rs1 with a member running on port 27017 on mongodb0.example.net , issue the following command: • To add a shard for a standalone mongod on port 27017 of mongodb0.example.net , issue the fol- lowing command: Note: It might take some time for chunks to migrate to the new shard. Before you can shard a collection, you must enable sharding for the collection’s database. Enabling sharding for a database does not redistribute data but make it possible to shard the collections in that database. Once you enable sharding for a database, MongoDB assigns a primary shard for that database where MongoDB stores all data before sharding begins. 1. From a mongo shell, connect to the mongos instance. Issue a command using the following syntax: 2. Issue the sh.enableSharding() method, specifying the name of the database for which to enable sharding. Use the following syntax: Optionally, you can enable sharding for a database using the enableSharding command, which uses the following syntax: You enable sharding on a per-collection basis. Enable Sharding for a Collection 1. Determine what you will use for the shard key . Your selection of the shard key affects the efficiency of sharding. See the selection considerations listed in the Considerations for Selecting Shard Key (page 695). 2. If the collection already contains data you must create an index on the shard key using createIndex() . If the collection is empty then MongoDB will create the index as part of the sh.shardCollection() step. 10.3. Sharded Cluster Tutorials 693 Enable Sharding for a Database Changed in version 2.0.3. For MongoDB versions prior to 2.0.3, you must specify all members of the replica set. For example: sh.addShard( "rs1/mongodb0.example.net:27017" ) sh.addShard( sh.addShard( "mongodb0.example.net:27017" ) mongo --host <hostname of machine running mongos> --port <port mongos listens on> sh.enableSharding("<database>") db.runCommand( { enableSharding: <database> } )