I have followed the mongodb documentation to create a sharded cluster. I have created a config server replica set and shard replica set with 3 members each.Following is the procedure I followed as per the docs:
Step 1: Created config server replica set with 3 members:
mongod --configsvr --replSet "myrepl" --dbpath <path1> --port 27019
mongod --configsvr --replSet "myrepl" --dbpath <path2> --port 27020
mongod --configsvr --replSet "myrepl" --dbpath <path3> --port 27021
Step 2: Connected a mongo shell to one of the mongod instances:
mongo --host localhost --port 27019
Step 3: Initiated the replica set in the mongo shell created above:
rs.initiate(
{
_id: "myrepl",
configsvr: true,
members: [
{ _id : 0, host : "localhost:27019" },
{ _id : 1, host : "localhost:27020" },
{ _id : 2, host : "localhost:270" }
]
}
)
Step 4: Created shard replica sets:
mongod --shardsvr --replSet "shardrepl" --dbpath <path1> --port 37019
mongod --shardsvr --replSet "shardrepl" --dbpath <path2> --port 37020
mongod --shardsvr --replSet "shardrepl" --dbpath <path3> --port 37021
Step 5: Connected to one member of the replica set and initiated the replica set:
mongo --host localhost --port 37019
rs.initiate(
{
_id : "shardrepl",
members: [
{ _id : 0, host : "localhost:37019" },
{ _id : 1, host : "localhost:37020" },
{ _id : 2, host : "localhost:37021" }
]
}
)
Everything is fine till here, the problem is in the next step:
Step 6: Connect mongos to sharded cluster:
mongos --configdb "myrepl"/localhost:27019,localhost:27020
Further it is stated to connect a mongo shell to this this mongos instance using
mongo --host <hostname> --port <port>
But it's not explicitly stated which host or port to use here. What host or port should I use here? And where should I execute the further commands to add shards?
Although I had a strong feeling this won't work (and it didn't :p), I tried executing mongo --host localhost --port 27019
and executed sh.addShard("localhost:37019")
,it gave an error- "no such command addShard"
Kindly help me out here,thanks!