Adds a database instance or replica set to a sharded cluster. The optimal configuration is to deploy shards across replica sets. This method must be run on a mongos instance.

The sh.addShard() method has the following parameter:

Parameter Type Description
host string The hostname of either a standalone database instance or of a replica set. Include the port number if the instance is running on a non-standard port. Include the replica set name if the instance is a replica set, as explained below.

The sh.addShard() method has the following prototype form:


The host parameter can be in any of the following forms:



Do not use localhost for the hostname unless your configuration server is also running on localhost.

New in version 2.6: mongos installed from official .deb and .rpm packages have the bind_ip configuration set to by default.

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



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 Sharded Collection Balancing for more information.

Changed in version 2.6: Chunk migrations can have an impact on disk space. Starting in MongoDB 2.6, the source shard automatically archives the migrated documents by default. For details, see moveChunk directory.

Hidden Members


You cannot include a hidden member in the seed list provided to sh.addShard().


To add a shard on a replica set, 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:


Was this page helpful?

Yes No

Thank you for your feedback!

We're sorry! You can Report a Problem to help us improve this page.