- Reference >
mongoShell Methods >- Sharding Methods >
- sh.addShard()
sh.addShard()¶
On this page
Definition¶
-
sh.addShard(<url>)¶ Adds a shard replica set to a sharded cluster. This method must be run on a
mongosinstance.Important
mongoShell MethodThis page documents a
mongomethod. This is not the documentation for database commands or language-specific drivers, such as Node.js. To use the database command, see theaddShardcommand.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
The
sh.addShard()method has the following parameter:Parameter Type Description hoststring 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:
The
sh.addShard()method has the following prototype form:Warning
Do not use
localhostfor the hostname unless your config server is also running onlocalhost.mongosinstalled from official .deb and .rpm packages have thebind_ipconfiguration set to127.0.0.1by default.mongosuses"majority"for theaddShardcommand and its helpersh.addShard().
Considerations¶
Balancing¶
When you add a shard to a sharded cluster, you affect the balance of chunks among the shards of a cluster for all existing sharded collections. The balancer will begin migrating chunks so that the cluster will achieve balance. See Cluster Balancer for more information.
Chunk migrations can have an impact on disk space, as the source shard automatically archives the migrated documents by default. For details, see moveChunk directory.
Example¶
To add a shard, specify the name of the replica set and the hostname of at least one member of the replica set, as a seed. If you specify additional hostnames, all must be members of the same replica set.
The following example adds a replica set named repl0 and specifies
one member of the replica set: