Removing a member from a replica set

To remove a member from a replica set, first shut down the mongod instance using the command for that operating system. For example, in Debian/Ubuntu Linux, issue the following command:

sudo service mongod stop

Then, from one of the servers remaining in the replica set, enter the mongo shell and run rs.conf() to find the hostname of the server to remove. You then execute rs.remove( "<host>" ), where <host> is exactly as shown from the output of rs.conf():

This forces a new election, and a new primary will be chosen from among the remaining members. You may have to restart the mongod instances on the remaining ...

Get MongoDB 4 Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.