rs.remove: A Powerful MongoDB Utility That is Now Even Better

Maythee Uthenpong

Posted on: February 19, 2018

The MongoDB command line utility, rs.remove(), is used to remove a member from a replica set. Prior to MongoDB version 3.0, the rs.remove() command would cause elections to occur. However, starting with version 3.0 this is no longer the case. From version 3.0 onwards, the rs.remove operation will not cause any elections. This is good news for several reasons.

In MongoDB, a typical production environment consists of 3 or more data node replica sets. Sometimes there is a need to migrate a replica set member or the entire replica set to new hardware due to server maintenance or to a more powerful server.

A typical migration can be accomplished through extending the replica set to the new server (e.g., adding new replica set members on the new hardware) and then removing the old member on the old hardware.

After extending the replica set to new hardware, the typical process would be as follows:

Stop the mongod instance on the old server.

Remove the replica set member by either using the rs.remove method or the rs.reconfig method below, which would cause an election:

Both methods of replica set removal (prior to version 3.0 for rs.remove) caused an election. So, in a production environment, this could have some impact on the application side depending on client side driver settings and the application code itself.

With this in mind, if you are running version 3.0 or higher, the recommended approach would now be to use the rs.remove() method versus the rs.reconfig wherever possible to remove a member of the replica set. The rs.remove() method no longer causes an election.