Removing a node from the replica set
MyReplicaSet:PRIMARY> rs.status()['members']
[
{
"_id" : 0,
"name" : "localhost:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 1108,
"optime" : {
"ts" : Timestamp(1527847161, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-06-01T09:59:21Z"),
"electionTime" : Timestamp(1527846189, 2),
"electionDate" : ISODate("2018-06-01T09:43:09Z"),
"configVersion" : 2,
"self" : true
},
{
"_id" : 1,
"name" : "localhost:27018",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 178,
"optime" : {
"ts" : Timestamp(1527847161, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1527847161, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-06-01T09:59:21Z"),
"optimeDurableDate" : ISODate("2018-06-01T09:59:21Z"),
"lastHeartbeat" : ISODate("2018-06-01T09:59:29.066Z"),
"lastHeartbeatRecv" : ISODate("2018-06-01T09:59:28.171Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "localhost:27017",
"configVersion" : 2
}
]
Remove the last node in the replica set
MyReplicaSet:PRIMARY> rs.remove('localhost:27018')
{
"ok" : 1,
"operationTime" : Timestamp(1527847202, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1527847202, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
MyReplicaSet:PRIMARY> rs.status()['members']
[
{
"_id" : 0,
"name" : "localhost:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 1205,
"optime" : {
"ts" : Timestamp(1527847261, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-06-01T10:01:01Z"),
"electionTime" : Timestamp(1527846189, 2),
"electionDate" : ISODate("2018-06-01T09:43:09Z"),
"configVersion" : 3,
"self" : true
}
]
Connect to the last replica set node, which we removed, and check rs.status()
mongo mongodb://localhost:27018
MyReplicaSet:OTHER> rs.status()
{
"state" : 10,
"stateStr" : "REMOVED",
"uptime" : 440,
"optime" : {
"ts" : Timestamp(1527847202, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-06-01T10:00:02Z"),
"infoMessage" : "could not find member to sync from",
"ok" : 0,
"errmsg" : "Our replica set config is invalid or we are not a member of it",
"code" : 93,
"codeName" : "InvalidReplicaSetConfig",
"operationTime" : Timestamp(1527847202, 1),
"$clusterTime" : {
"clusterTime" : Timestamp(1527847202, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}