- Reference >
- Database Commands >
- Sharding Commands >
- addShard
addShard¶
On this page
Definition¶
-
addShard¶ Adds either a database instance or a replica set to a sharded cluster. The optimal configuration is to deploy shards across replica sets.
Run
addShardwhen connected to amongosinstance. The command takes the following form when adding a single database instance as a shard:When adding a replica set as a shard, use the following form:
The command contains the following fields:
Field Type Description addShardstring The hostname and port of the mongodinstance to be added as a shard. To add a replica set as a shard, specify the name of the replica set and the hostname and port of a member of the replica set.maxSizeinteger Optional. The maximum size in megabytes of the shard. If you set maxSizeto0, MongoDB does not limit the size of the shard.namestring Optional. A name for the shard. If this is not specified, MongoDB automatically provides a unique name. The
addShardcommand stores shard configuration information in the config database. Always runaddShardwhen using theadmindatabase.Specify a
maxSizewhen you have machines with different disk capacities, or if you want to limit the amount of data on some shards. ThemaxSizeconstraint prevents the balancer from migrating chunks to the shard when the value ofmem.mappedexceeds the value ofmaxSize.
Important
You cannot include a hidden member in the seed list provided to
addShard.
Examples¶
The following command adds the database instance running on
port 27027 on the host mongodb0.example.net as a shard:
Warning
Do not use localhost for the hostname unless your
configuration server is also running on
localhost.
The following command adds a replica set as a shard:
You may specify all members in the replica set. All additional hostnames must be members of the same replica set.