How to reset MongoDB replica set settings

Solution 1:

If you want to keep the data, but start outside a replica set, just restart the mongod process without the --replSet and 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.replset collection is empty.

Once that is done, and you are happy with your standalone instance, you can then restart with a different --replSet argument and go through the replica set configuration process again:

http://www.mongodb.org/display/DOCS/Replica+Set+Configuration

The other option, as you mention, is to remove all the data files and start completely from scratch.

Solution 2:

You do not need to remove any database files in order to reset the configuration of your replica set.

To reset the configuration, make sure every node in your replica set is stopped. Then delete the "local" database for every node.

Once you are confident all nodes are not running and the "local" database are gone, start the mongod process again (of course using the --replSet flag). Then run rs.initiate().


Solution 3:

  1. Go to mongo shell on Secondary servers

2)Stop the secondary servers by using below command :

use admin db.shutdownServer()

2] Go to Linux shell- on secondary servers and type below command :

sudo service mongod stop

Starting the MongoDB replication -

  • Go to Linux shell - on secondary servers and type below command :

    sudo service mongod start Starting the MongoDB replication -

  • Go to primary and type below commands to start the replication :

a] rs.initiate()

b] rs.add("Secondar -1:port no")

c] rs.add("Secondary-2:port no")

d] rs.add({ "_id" : 3, "host" : "Hidden_member:port no", "priority" : 0, "hidden" : true })

e] rs.status()

For more information, Please check the below link : http://www.tutorial-points.com/2016/03/stopping-and-starting-mongodb.html


Solution 4:

  1. edit /etc/mongod.conf and comment out replication: block
  2. service mongod restart
  3. mongo local --eval "db.dropDatabase()"
  4. service mongod stop
  5. on mongo primary : rs.add("this node")
  6. edit /etc/mongod.conf and uncomment the replication: block
  7. service mongod restart

Your node will get added to the existing replica set and will start syncing to the existing primary

Tags:

Mongodb