Search code examples
mongodbreplication

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.


Solution

  • 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.