sh.addShard()
Definition
sh.
addShard
() - Adds a shard replica set to a sharded cluster. This methodmust be run on a
mongos
instance.
The sh.addShard()
method has the following parameter:
ParameterTypeDescriptionhost
stringThe replica set name, hostname, and port of at least one member ofthe shard’s replica set. Any additional replica set member hostnamesmust be comma separated. For example:
- <replica_set>/<hostname><:port>,<hostname><:port>, ...
The sh.addShard()
method has the following prototype form:
- sh.addShard("<replica_set>/<hostname><:port>")
Warning
Do not use localhost
for the hostname unless yourconfig serveris also running on localhost
.
New in version 2.6: mongos
installed from official .deb and .rpm packageshave the bind_ip
configuration set to 127.0.0.1
bydefault.
mongos
uses"majority"
for theaddShard
command and its helpersh.addShard()
.
The sh.addShard()
method is a helper for theaddShard
command. The addShard
command hasadditional options which are not available with this helper.
Considerations
Balancing
When you add a shard to a sharded cluster, you affect the balance ofchunks among the shards of a cluster for all existing shardedcollections. The balancer will begin migrating chunks so that thecluster will achieve balance. See Cluster Balancer formore information.
Changed in version 2.6: Chunk migrations can have an impact on disk space. Starting inMongoDB 2.6, the source shard automatically archives the migrateddocuments by default. For details, see moveChunk directory.
Hidden Members
Important
You cannot include a hidden member in the seed list provided tosh.addShard()
.
Example
To add a shard, specify the name of the replica set andthe hostname of at least one member of the replica set, as a seed. Ifyou specify additional hostnames, all must be members of the samereplica set.
The following example adds a replica set named repl0
and specifiesone member of the replica set:
- sh.addShard("repl0/mongodb3.example.net:27327")