- 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
maxSize
is0
then MongoDB will not limit the size of the shard.
Use the
addShard
command to add a database instance or replica set to a sharded cluster. You must run this command when connected amongos
instance.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
localhost
for 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.
addShard
takes the following form:Example
If you specify additional hostnames, all must be members of the same replica set.
Send this command to only one
mongos
instance, it will store shard configuration information in the config database.Note
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 value ofmem.mapped
exceeds the value ofmaxSize
.