3

I want to cluster MongoDB by using a replica set. I have created a three-node replicaset (rs0,rs1,rs2), and run the DBs in parallel with no issues. But when I shut down any two instance (one primary and secondary), the remaining secondary member is not made the primary, instead it remains as a secondary.

Step1:

  • rs0: primary
  • rs1: secondary
  • rs2: secondary

Every thing is ok. When

Step2:

  • rs0: stopped
  • rs1: stopped
  • rs2: secondary (This is not promoted to primary)

Why?

1 Answer 1

3

This is by design. If you want to run with only one node, restart that node without replica set switch.

If a majority of the replica set is inaccessible or unavailable to the current primary, the primary will step down and become a secondary. The replica set cannot accept writes after this occurs, but remaining members can continue to serve read queries if such queries are configured to run on secondaries.

Read these resources for more details:

  1. Replica Set Elections
  2. mongo replica set to single server
  3. Voting in MongoDB
1
  • What if this happens in production? if all secondary nodes fail, then can't anybody perform insert operation anymore?
    – Rahul
    Commented Aug 25, 2022 at 3:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.