MongoDB – How to Reset Mongo Replica Set

The following instructions would help you to reset MongoDB replica set settings and start over with replication all over again. These are especially helpful for developers starting to learnĀ MongoDB replication.

  • Shut down the mongodb server
  • Start the mongodb server in the standalone mode, e.g., without –replSet <replicaSetName>.
  • Login to Mongodb; You can use admin database
  • Make sure that user has readWrite permission to local database. In case, it is not, use following command to grant the role to the user. The following command gives readWrite permission on local database to admin user.
    db.grantRolesToUser("admin", [{role: "readWrite", db: "local"}]);
  • Switch to local database
  • Execute the command to make the cllection such as system.replset empty
  • Make sure that system.replset in local database is empty by executing the following command:
  • Start the MongoDB database with replSet option all over again; The following command can be used:
    sudo mongod --dbpath /path/to/mongo/db --replSet rs0
  • Login to Mongodb using admin user and execute following command to initialize the replication set:
  • Switch over to local database and execute following command to make sure that there exists an entry for the replication.
Ajitesh Kumar
Follow me
Latest posts by Ajitesh Kumar (see all)

Ajitesh Kumar

I have been recently working in the area of Data Science and Machine Learning / Deep Learning. In addition, I am also passionate about various different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia etc and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data etc. I would love to connect with you on Linkedin.
Posted in MongoDB, NoSQL. Tagged with , .

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.