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

Leave A Reply

Time limit is exhausted. Please reload the CAPTCHA.