DEV Community

abhishekjaindba
abhishekjaindba

Posted on

1 1

How to Rebuild MongoDB Replica-Set Node Fast in Few Minutes

It sometimes happens that the MongoDB replica set node goes out of sync from replica set members and, due to high lag, cannot synchronise itself from the replica set. There are traditional ways to remove the replica set node from the cluster and add it back but the issue arises when your database size is too big and node sync takes hours or days. Also in some cases, it degrades the performance. You simply use the following steps and rebuild your replica set member in a few minutes.

Step1
Remove the node from cluster

Prod:PRIMARY> rs.remove(":27017")
Step2
login to ssh to Secondary Node and delete all the content of mongodb directory folder

Step3
Log in to the Primary node. If you don’t know who is primary run this command rs. slave(ok) from any node and then run rs.status(). rs. status will give you the [rimary node IP address or Hostname. Just ssh or login to primary and shut the MongoDB services

--Stop MongoDB

Read more: https://thedbadmin.com/how-to-rebuild-mongodb-replica-set-node-fast-in-few-minutes/

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay