This version of the documentation is archived and no longer supported.


  • 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:


You can specify shards using the hostname, or a hostname and port combination if the shard is running on a non-standard port.


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.




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