mongodb 3.2: Error when adding shards as part of batch script step

52 views
Skip to first unread message

Maaz Qureshi

unread,
Jun 12, 2018, 7:52:07 PM6/12/18
to mongodb-user
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. 

Kevin Adistambha

unread,
Jun 25, 2018, 3:27:41 AM6/25/18
to mongodb-user

Hi

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.

This implies that the reconfig step did not finish its work before you add the shards. This error described the situation:

... host localhost:10001 does not belong to replica set test1; found { hosts: [ \"mqureshi:10001\" ] ...

Which says that it cannot find localhost:10001, but the replica set contains mqureshi:10001.

If you’re trying to setup a sharded cluster development environment locally, you might be able to use mtools. It contains mlaunch, which was designed for this purpose.

For example using mlaunch, you can replicate the setup in your post by executing:

mlaunch init --sharded 2 --replicaset --nodes 1

Note that mlaunch was for development purposes only. It is not recommended to be used for a production environment.

Best regards
Kevin

Reply all
Reply to author
Forward
0 new messages