I'm writing a batch script to setup a local mongodb environment for a project. Here are just the mongo shell commands that I'm running in batch file:
.\mongod.exe --port 10001 --dbpath C:\mongodb\data1 --replSet test1 --shardsvr
.\mongod.exe --port 10002 --dbpath C:\mongodb\data2 --replSet test2 --shardsvr
.\mongod.exe --port 27019 --dbpath C:\mongodb\config --replSet config --configsvr
.\mongo.exe --port 10001 --eval 'rs.initiate(); c=rs.conf(); c.members[0].host="localhost:10001"; rs.reconfig(c); quit();'
.\mongo.exe --port 10002 --eval 'rs.initiate(); c=rs.conf(); c.members[0].host="localhost:10002"; rs.reconfig(c); quit();'
.\mongo.exe --port 27019 --eval 'rs.initiate(); c=rs.conf(); c.members[0].host="localhost:27019"; rs.reconfig(c); quit();'
.\mongos.exe --configdb 'localhost:27019'
.\mongo.exe --eval 'sh.addShard("test1/localhost:10001"); sh.addShard("test2/localhost:10002"); sh.enableSharding("Test");'
Everything works fine except the last step where I get the following errors:
sh.addShard("test1/localhost:10001")
{
"ok" : 0,
"errmsg" : "in seed list test1/localhost:10001, host localhost:10001 does not belong to replica set test1; found { hosts: [ \"mqureshi:10001\" ], setName: \"test1\", setVersion: 1, ismaster: true, secondary: false, primary: \"mqureshi:10001\", me: \"mqureshi:10001\", electionId: ObjectId('7fffffff0000000000000001'), maxBsonObjectSize: 16777216, maxMessageSizeBytes: 48000000, maxWriteBatchSize: 1000, localTime: new Date(1528829089143), maxWireVersion: 4, minWireVersion: 0, ok: 1.0 }",
"code" : 96
}
sh.addShard("test2/localhost:10002")
{
"ok" : 0,
"errmsg" : "in seed list test2/localhost:10002, host localhost:10002 does not belong to replica set test2; found { hosts: [ \"mqureshi:10002\" ], setName: \"test2\", setVersion: 1, ismaster: true, secondary: false, primary: \"mqureshi:10002\", me: \"mqureshi:10002\", electionId: ObjectId('7fffffff0000000000000001'), maxBsonObjectSize: 16777216, maxMessageSizeBytes: 48000000, maxWriteBatchSize: 1000, localTime: new Date(1528829640252), maxWireVersion: 4, minWireVersion: 0, ok: 1.0 }",
"code" : 96
}
sh.enableSharding("Test")
{ "ok" : 0, "errmsg" : "No shards found", "code" : 70 }
I was able to set it up successfully by running the steps individually (including the javascript) however, it fails when run as a batch step.