- Reference >
- Database Commands >
- addShard
addShard¶
-
addShard¶ Parameters: - hostname (string) – a hostname or replica-set/hostname string.
- name (string) – Optional. Unless specified, a name will be automatically provided to uniquely identify the shard.
- maxSize (integer) – Optional, megabytes. Limits the maximum size
of a shard.
If
maxSizeis0then MongoDB will not limit the size of the shard.
Use the
addShardcommand to add a database instance or replica set to a sharded cluster. You must run this command when connected amongosinstance.The command takes the following form:
Example
Replace
<hostname><:port>with the hostname and port of the database instance you want to add as a shard.Warning
Do not use
localhostfor the hostname unless your configuration server is also running onlocalhost.The optimal configuration is to deploy shards across replica sets. To add a shard on a replica set you must specify the name of the replica set and the hostname of at least one member of the replica set. You must specify at least one member of the set, but can specify all members in the set or another subset if desired.
addShardtakes the following form:Example
If you specify additional hostnames, all must be members of the same replica set.
Send this command to only one
mongosinstance, it will store shard configuration information in the config database.Note
Specify a
maxSizewhen you have machines with different disk capacities, or if you want to limit the amount of data on some shards.The
maxSizeconstraint prevents the balancer from migrating chunks to the shard when the value ofmem.mappedexceeds the value ofmaxSize.