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. 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.

View Comments

Share
Published by
Ajitesh Kumar
Tags: mongodbnosql

Recent Posts

Agentic Reasoning Design Patterns in AI: Examples

In recent years, artificial intelligence (AI) has evolved to include more sophisticated and capable agents,…

2 months ago

LLMs for Adaptive Learning & Personalized Education

Adaptive learning helps in tailoring learning experiences to fit the unique needs of each student.…

2 months ago

Sparse Mixture of Experts (MoE) Models: Examples

With the increasing demand for more powerful machine learning (ML) systems that can handle diverse…

3 months ago

Anxiety Disorder Detection & Machine Learning Techniques

Anxiety is a common mental health condition that affects millions of people around the world.…

3 months ago

Confounder Features & Machine Learning Models: Examples

In machine learning, confounder features or variables can significantly affect the accuracy and validity of…

3 months ago

Credit Card Fraud Detection & Machine Learning

Last updated: 26 Sept, 2024 Credit card fraud detection is a major concern for credit…

3 months ago