Starting over with replica configuration in mongodb

obeq picture obeq · Nov 28, 2012 · Viewed 22k times · Source

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.

Answer

rbrc picture rbrc · May 31, 2013

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.