« Back to Blog

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

Maythee Uthenpong

By 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:

  1. Stop the mongod instance on the old server.
  2. Remove the replica set member by either using the rs.remove method or the rs.reconfig method below, which would cause an election:
new_config = rs.conf();
new_config.members.splice(<member id nbr>,<1>);

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.

Have questions about managing MongoDB? Access to our DBAs with deep MongoDB expertise is always included with every instance, even with free trials. Start focusing on development and let us handle the MongoDB management.

eBook: Everything you need to know about DBaaS

Learn why DBaaS is booming and get a checklist of questions to ask vendors to find the right fit for your business.

Learn More →

DBaaS for Elasticsearch JetpackeBook: DBaaS for Elasticsearch JetpackEverything you need to know about Elasticsearch with Kibana. Plus, learn how DBaaS can save you time and money.Learn More →

Keep in the know!

Subscribe to our emails and we’ll let you know what’s going on at ObjectRocket. We hate spam and make it easy to unsubscribe.