- Reference >
- JavaScript Methods >
- sh.addShard()
sh.addShard()¶
-
sh.
addShard
(host)¶ Parameters: - host (string) – Specify the hostname of a database instance or a replica set configuration.
Use this method to add a database instance or replica set to a sharded cluster. This method must be run on a
mongos
instance. Thehost
parameter can be in any of the following forms:You can specify shards using the hostname, or a hostname and port combination if the shard is running on a non-standard port.
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.
sh.addShard()
takes the following form:If you specify additional hostnames, all must be members of the same replica set.
Example
The
sh.addShard()
method is a helper for theaddShard
command. TheaddShard
command has additional options which are not available with this helper.