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


  • hostname (string) – a hostname or replica-set/hostname string.
  • name (string) – Optional. Unless specified, a name will be automatically provided to uniquely identify the shard.
  • maxSize (integer) – Optional, megabytes. Limits the maximum size of a shard. If maxSize is 0 then MongoDB will not limit the size of the shard.

Use the addShard command to add a database instance or replica set to a sharded cluster. You must run this command when connected a mongos instance.

The command takes the following form:

{ addShard: "<hostname><:port>" }


db.runCommand({addShard: ""})

Replace <hostname><:port> with the hostname and port of the database instance you want to add as a shard.


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. addShard takes the following form:

{ addShard: "replica-set/hostname:port" }


db.runCommand( { addShard: "repl0/"} )

If you specify additional hostnames, all must be members of the same replica set.

Send this command to only one mongos instance, it will store shard configuration information in the config database.


Specify a maxSize when you have machines with different disk capacities, or if you want to limit the amount of data on some shards.

The maxSize constraint prevents the balancer from migrating chunks to the shard when the value of mem.mapped exceeds the value of maxSize.