If anyone wants to reset their replica set, please follow the steps along.
Removing a Member from Replica Set:
Shutdown your node which you want to remove. Two ways to do this:
Kill the mongod process by checking pid through the command below. The first column will show
pid. Make sure you kill only the respective node process.
vagrant@m103:~$ ps -ef | grep mongod 501 2809 2568 0 5:12PM ttys000 0:00.00 grep mongod --port 27002 --dbpath... 520 2809 2568 0 5:12PM ttys000 0:00.00 grep mongod --port 27001 --dbpath... vagrant@m103:~$ kill 501
Or Connect to the respective node, run:
Connect to your primary node of your replica set using
mongo --port 27xxx
Authenticate yourself on
> use admin > db.auth("m103-admin","m103-pass")
Removing a Replica Set as Whole:
*Note: During this process, one might lose their data. So, you may want to keep a backup of data files.
If you want to keep the data, but start outside a replica set, just restart the mongod process without the
--replSetand on a different port. That will give you a standalone mongod.
To be completely sure that the replica set configuration is gone from the instance, make sure that the
local.system.replsetcollection is empty.
Connect to primary node
Authenticate yourself as mentioned above using
Once that is done, and you are happy with your standalone instance, you can then restart with a different
--replSetargument and go through the replica set configuration process again:
The other option, as you mention, is to remove all the data files and start completely from scratch.
Remove dbPath directory using
rm -rf. Example:
vagrant@m103:~$ rm -rf /var/mongdb/db/node2
Follow the steps mentioned in the lab again.
Let me know if you have any doubts!