This page documents a
mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.
For the database command, see the
For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
For the legacy
mongoshell documentation, refer to the documentation for the corresponding MongoDB Server release:
sh.addShard()method has the following parameter:ParameterTypeDescription
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:
sh.addShard()method has the following prototype form:
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 Balancer Internals for more information.
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: