Navigation
This version of the manual is no longer supported.

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. The host parameter can be in any of the following forms:

[hostname]
[hostname]:[port]
[set]/[hostname]
[set]/[hostname],[hostname]:port

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 on localhost.

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.

sh.addShard("set-name/seed-hostname")

Example

sh.addShard("repl0/mongodb3.example.net:27327")

The sh.addShard() method is a helper for the addShard command. The addShard command has additional options which are not available with this helper.