1

We are using mongoDB 3.0, and our setup uses six instances with one PRIMARY and the rest of them as SECONDARY.

We were trying to remove three of these using the following command sequence -

rs.remove("host1:port") //same for host2, host3

Now that we wanted to add those back, there is a weird state that the rs.conf() results in. i.e

The replica set before removal was at the _id:1,2 and 3 Now that we have added them back, they are at the _id:7,8, and 9

Why does this happen so, and how do I correct the rs.conf()?

Also if I again try and remove host1, host2 or host3, they are not getting removed.

rs.remove("host1:port")

displays the conf() value back again, so we are unable to remove them now. Is there a way to overcome from such state?


rs.conf()

{
    "_id" : "shard1",
    "version" : 15,
    "members" : [
        ...
        {
            "_id" : 4,
            "host" : "host4:port",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 1,
            "tags" : {

            },
            "slaveDelay" : 0,
            "votes" : 1
        },
        {
            "_id" : 5,
            "host" : "host5:port",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 1,
            "tags" : {

            },
            "slaveDelay" : 0,
            "votes" : 1
        },
        {
            "_id" : 8,
            "host" : "host1:port",
            "arbiterOnly" : false,
            "buildIndexes" : true,
            "hidden" : false,
            "priority" : 1,
            "tags" : {

            },
            "slaveDelay" : 0,
            "votes" : 1
        }
    ],
    "settings" : {
        "chainingAllowed" : true,
        "heartbeatTimeoutSecs" : 10,
        "getLastErrorModes" : {

        },
        "getLastErrorDefaults" : {
            "w" : 1,
            "wtimeout" : 0
        }
    }
}
2
  • What does your current rs.conf() look like? Do you get any error message when trying to remove a member? It is expected that the member _ids will change if you remove and re-add a member so I wouldn't be concerned about those incrementing. Also, what specific version of MongoDB 3.0 are you using?
    – Stennie
    Aug 3 '17 at 21:05
  • @Stennie Updated the rs.conf() in question and we are using mongo 3.0.4. Do you get any error message when trying to remove a member? No, the rs.conf() gets displayed as is.
    – Naman
    Aug 4 '17 at 2:42
1

When you add hosts, _id is set always one bigger than what is current max _id. If you really want to "fix" that, you can always do:

var cfg=rs.conf()
cfg.member[3]._id=0
cfg.member[4]._id=1
rs.reconfig(cfg)

Same way, you can change anything or everything in your rs configuration. Remove or add new hosts, change an order of hosts in the list.

7
  • there is still half answered, I am unable to remove the replica set, which is the major problem currently
    – Naman
    Aug 3 '17 at 18:16
  • You can remove that replica set with that rs.reconfig(cfg) procedure. As I said, you can do ANY change! After change (removing that node), that node will receive this new configuration and will drop out from replica set, because it doesn't belong in it anymore.
    – JJussi
    Aug 4 '17 at 4:18
  • Well the remove part doesn't seem to be working for me, as already mentioned in the question.
    – Naman
    Aug 5 '17 at 5:13
  • 1
    Just rs.conf(), copy members part to your text editor, remove wanted node, copy that member part back to clipboard, then var cfg=rs.conf(); cfg.members=<paste here>; rs.reconfig(cfg);
    – JJussi
    Aug 5 '17 at 9:12
  • that works, but why would rs.remove("") not work?
    – Naman
    Aug 5 '17 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.