Question :
As I am new with MongoDB.
I have configured 2 config server, 2 shards and all are connected with mongod client. Also, One Mongos client is UP and Running.
I am currenctly implementing Sharding using Mongo Zone. As I have to store the data accourding to country/Zone. But facing below error in shards:
2018-05-03T16:22:40.200+0530 W SHARDING [conn13] Chunk move failed :: caused by ::
NoShardingEnabled: Cannot accept sharding commands if not started with --shardsvr
2018-05-03T16:27:11.223+0530 I SHARDING [Balancer] Balancer move testdb.user:
[{ zipcode: "380001" }, { zipcode: "39000" }), from rs1, to rs0 failed :: caused by ::
NoShardingEnabled: Cannot accept sharding commands if not started with --shardsvr
I have already started server with --shardsvr
and also mentioned in config file as well. But still I am facing issue.
Below are the all config files:
mongosconfig.cfg
systemLog:
destination: file
path: "c:\data\log\mongos.log"
logAppend: true
sharding:
configDB: "rs0/192.168.1.113:27017,192.168.1.112:27017"
net:
bindIp: 192.168.1.113
port: 27018
mongoclientconfig.cfg – configserver1
systemLog:
destination: file
path: "c:\data\log\mongoclient.log"
logAppend: true
storage:
dbPath: "c:\data\db\configdb"
journal:
enabled: true
sharding:
clusterRole: "configsvr"
net:
bindIp: 192.168.1.113
port: 27017
replication:
replSetName: "rs0"
mongodconfig.cfg – shard1
systemLog:
destination: file
path: "c:\data\log\mongod.log"
logAppend: true
storage:
dbPath: "c:\data\db\clientdb"
journal:
enabled: true
sharding:
clusterRole: "shardsvr"
net:
bindIp: 192.168.1.113
port: 27019
replication:
replSetName: "rs0"
mongoclientconfig.cfg – configserver2
systemLog:
destination: file
path: "D:\data\log\mongoclient.log"
logAppend: true
storage:
dbPath: "D:\data\db\configdb"
journal:
enabled: true
sharding:
clusterRole: "configsvr"
replication:
replSetName: "rs1"
net:
bindIp: 192.168.1.112
port: 27017
mongodconfig.cfg – Shard2
systemLog:
destination: file
path: "D:\data\log\mongod.log"
logAppend: true
storage:
dbPath: "D:\data\db\clientdb"
journal:
enabled: true
sharding:
clusterRole: "shardsvr"
net:
bindIp: 192.168.1.112
port: 27019
replication:
replSetName: "rs1"
Below are the commands which i have used for zone wise sharding as per the mongodb documentation(official):
rs.initiate({_id: "rs0",members: [{ _id : 0, host : "192.168.1.113:27019" }]}) //for shard1
rs.initiate({_id: "rs1",members: [{ _id : 1, host : "192.168.1.112:27019" }]}) //for shard2
sh.addShard("rs0/192.168.1.113:27019"); //Adding shard1 from mongos client
sh.addShard("rs1/192.168.1.112:27019"); //Adding shard2 from mongos client
sh.addShardToZone("rs0","IND");
sh.addShardToZone("rs1","UK");
sh.addTagRange("testdb.user", {zipcode: "380001"}, {zipcode: "390000"},
"IND");
sh.addTagRange("testdb.user", {zipcode: "400000"}, {zipcode: "600000"},
"UK");
sh.shardCollection("testdb.user", { zipcode: 1 } );
Please help me get this resolve.
Thanks in Advance.
Answer :
Problem here is your replSetName:
parameters.
BOTH config servers must be at same replica set, f.ex. conf
and then those shards (data nodes) both should have different replica set names. f.ex. rs0 and rs1.
Now your config1 is rs0
and config2 is rs1
.