Greg
Greg

Reputation: 11542

Mongo Replica Sets

I just set up a replica set according to the instructions online.

I have config like this:

{
    "_id" : "rs0",
    "members" : [
        {
            "_id" : 0,
            "host" : "10.0.8.10:27017"
        }
    ]
}

I ran the rs.initiate() command. No issues.

Ok, so I went to set up the second node I did the same thing (with a different IP of course). Again I ran the rs.initiate() command without issues.

I ran the rs.add command, providing the IP/port of my first instance. No problem.

Finally from the other node I ran the rs.add command with the reference to the former node. Now I got this:

rs0:PRIMARY> rs.add("10.0.0.10:27017");
{
    "errmsg" : "exception: member 10.0.0.10:27017 has a config version >= to the new cfg version; cannot change config",
    "code" : 13341,
    "ok" : 0
}

What does that mean? And how do I fix it? Both nodes were created from identical Mongo releases.

Upvotes: 1

Views: 3090

Answers (2)

jeffl
jeffl

Reputation: 446

The rs.initiate() command should only be used once for any given replicaset. You have the option of specifying all members of the set as options to the command like so:

rs.initiate({_id:'rs0', members:[{_id:0, host:'10.0.8.10:27017'},{_id:1, host:'10.0.0.10:27017'}]})

Once the replicaset is configured, you can add new members using rs.add(). If you choose this method, you would initialize the set with a single member, then execute rs.add() from the PRIMARY.

rs.initiate({_id:'rs0', members:[{_id:0, host:'10.0.8.10:27017'}]})
rs.add('10.0.8.10:27017')

Upvotes: 2

friedo
friedo

Reputation: 67048

You don't need to run rs.initiate() on the other node. Once the node is added to the config, running rs.initiate() on the first node will initiate the entire replica set.

The error is caused because the replica set has already been initiated with the config version you set up when you run rs.initiate() a second time.

Upvotes: 2

Related Questions