obeq
obeq

Reputation: 675

Starting over with replica configuration in mongodb

I did a mistake when configuring replica sets in mongodb. I think that what I did wrong is that I did a rs.initialize() on both nodes, which made them confused in some way. I'm not sure.

Now all I want to do is start over, but I couldn't find a way to de-initialize a node. So I followed the advice to delete the local* db files, thus resetting the configurations. I did that, and now nothing works.

> rs.initiate()
{
    "info2" : "no configuration explicitly specified -- making one",
    "me" : "0.0.0.0:27017",
    "errmsg" : "couldn't initiate : can't find self in the replset config",
    "ok" : 0
}
> rs.conf()
null

I tried to remove and reinstall the package (I'm doing this on Ubuntu servers) which just meant that my mongodb.conf disappeared and my init script stopped working. This is of course easy enough to solve.

So how do I start over?

Note: I did look at this answer, but since rs.conf() doesn't work this doesn't work either.

Upvotes: 17

Views: 23642

Answers (3)

occasl
occasl

Reputation: 5454

If you just comment out bind_ip in /etc/mongod.conf this will achieve the correct result so that you can reissue a rs.initiate() command to set-up or reconfig the replica.

Upvotes: 9

rbrc
rbrc

Reputation: 871

You'll also get this error if your machine's hostname doesn't map back to 127.0.0.1. Update your /etc/hosts and/or your /etc/hostname, and rs.initiate() with no config should work.

Upvotes: 54

Andre de Frere
Andre de Frere

Reputation: 2743

If you force a reconfig with a config that you have generated, does it resolve the issue?

You could do this similar to the follow from the {{mongo}} shell:

> cfg = {
...     "_id" : "rs0",
...     "version" : 1,
...     "members" : [
...         {
...             "_id" : 0,
...             "host" : "0.0.0.0:27017"
...         }
...     ]
... }

>rs.reconfig(cfg, {force:true})

You may need to tune the cfg variable to have your hostname and portname, as the can't find self in new replset config error will be returned to the shell if the repl set can't find the node it is running from in the config.

Upvotes: 26

Related Questions