Adds a shard replica set to a sharded cluster.

Run addShard when connected to a mongos instance. The command takes the following form to add a shard replica set:

{ addShard: "<replica_set>/<hostname><:port>", maxSize: <size>, name: "<shard_name>" }

The command contains the following fields:

Field Type Description
addShard string

The replica set name, hostname, and port of at least one member of the shard’s replica set. Any additional replica set member hostnames must be comma separated. For example:

<replica_set>/<hostname><:port>,<hostname><:port>, ...
maxSize integer Optional. The maximum size in megabytes of the shard. If you set maxSize to 0, MongoDB does not limit the size of the shard.
name string Optional. A name for the shard. If this is not specified, MongoDB automatically provides a unique name.

The addShard command stores shard configuration information in the config database. Always run addShard when using the admin database.

Specify a maxSize when you have machines with different disk capacities, or if you want to limit the amount of data on some shards. The maxSize constraint prevents the balancer from migrating chunks to the shard when the totalSize returned from running listDatabases on the shard exceeds the value of maxSize.





Hidden Members


You cannot include a hidden member in the seed list provided to addShard.


The following command adds a replica set as a shard:

use admin
db.runCommand( { addShard: "repl0/"} )


Do not use localhost for the hostname unless your config server is also running on localhost.