To create a sharded cluster, you need to add servers configured as shard servers under the following conditions:
- You need to open a mongo shell on a mongos instance that's been configured for the sharded cluster you are building.
- You need to have been granted the appropriate cluster administration role (https://docs.mongodb.com/manual/reference/built-in-roles/#cluster-administration-roles).
The shell command to add a shard is sh.addShard(). Here is the generic syntax:
sh.addShard("REPLICA_SET/MEMBER:PORT[,MEMBER:PORT]");
REPLICA_SET represents the name of the replica set hosting the shard. MEMBER is the DNS or resolvable hostname of the replica set member. PORT defaults to 27018 (not the same as a standalone mongod instance)!
If sharding has been enabled for the database, when you execute sh.addShard(), the sharded cluster balancer immediately starts moving chunks to the new shard. Be prepared for a high initial volume of database...