Categories: MongoDBNoSQL

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
    db.system.replset.remove({});
    
  • Make sure that system.replset in local database is empty by executing the following command:
    db.system.replset.find();
    
  • 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:
    rs.initiate();
    
  • Switch over to local database and execute following command to make sure that there exists an entry for the replication.
    db.system.replset.find();
    
Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about 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. For latest updates and blogs, follow us on Twitter. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking. Check out my other blog, Revive-n-Thrive.com

View Comments

Share
Published by
Ajitesh Kumar
Tags: mongodbnosql

Recent Posts

Feature Selection vs Feature Extraction: Machine Learning

Last updated: 2nd May, 2024 The success of machine learning models often depends on the…

5 mins ago

Model Selection by Evaluating Bias & Variance: Example

When working on a machine learning project, one of the key challenges faced by data…

6 hours ago

Bias-Variance Trade-off in Machine Learning: Examples

Last updated: 1st May, 2024 The bias-variance trade-off is a fundamental concept in machine learning…

1 day ago

Mean Squared Error vs Cross Entropy Loss Function

Last updated: 1st May, 2024 As a data scientist, understanding the nuances of various cost…

1 day ago

Cross Entropy Loss Explained with Python Examples

Last updated: 1st May, 2024 In this post, you will learn the concepts related to…

1 day ago

Logistic Regression in Machine Learning: Python Example

Last updated: 26th April, 2024 In this blog post, we will discuss the logistic regression…

6 days ago