Hi Kanika,
I’m Octavian from USA. I am mostly interested in database administration working for many years on DB2 LUW and Informix. Very interesting and informative course.
I am looking for best practice (script or steps) on how to cleaning existing nodes in inconsistent state already included to a replica set, to be able resync or remove and add the node back to and existent replica set. I have inadvertently run rs.initiate on a Seconday, so I ended up with 2 Primaries. I can use brute force to remove storage and re-initialize everything, but I was wondering is there is better way or command.?
I have found the following, but still does not work due to authorization ramifications on the old Seconday currently a Primary.
The scary part is rs.initiate was execute immediately without any warning to change the state from Secondary to Primary, but reversing the state seems impossible…
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.
1
db.grantRolesToUser("admin", [{role: "readWrite", db: "local"}]);
Switch to local database
Execute the command to make the cllection such as system.replset empty
1
db.system.replset.remove({});
Make sure that system.replset in local database is empty by executing the following command:
1
db.system.replset.find();
Start the MongoDB database with replSet option all over again; The following command can be used:
1
sudo mongod --dbpath /path/to/mongo/db --replSet rs0
Login to Mongodb using admin user and execute following command to initialize the replication set:
1
rs.initiate();
Switch over to local database and execute following command to make sure that there exists an entry for the replication.
1
db.system.replset.find();
TIA