Read and Write in the replica set

I have a small doubt in this topic from the course topic. When the primary is stepped down as secondary, and don’t have a majority vote in the election to elect a primary node. In this case, we have no primary node in the cluster. Also, we cannot do any write operation without a primary.

  1. In this situation what are the possibilities to regain full control over the replica-set?
  2. I thought about adding one more node to the replica set. However we still need to use rs.add() which won’t work with Secondary. Is my understanding wrong?
  3. Finally why is it a fail safe mechanism as instructor mentioned. I want someone to throw more light on this statement.

Hi :wave: @Akyas_Ahamed,

Welcome to the MongoDB Community forums :sparkles:

If you have a 3-member PSS(Primary, Secondary, Secondary), and if the current primary becomes unavailable or stepped down as secondary, an election determines the new primary. Refer Replica Set Elections for more details.

The election is first decided by priority. If both Nodes B & C have the same priority, then the one who is most up to date in respect to the failed primary (oplog) wins and becomes primary.

Correct :white_check_mark:, The replica set cannot process write operations until the election completes successfully. The replica set can continue to serve read queries if such queries are configured to run on secondaries.

If the primary node remains unavailable for longer than the configured timeout it triggers the automatic failover process. One of the remaining secondaries calls for an election to select a new primary and automatically resume normal operations, and we regain control over the replica set.

Correct :white_check_mark: To run the rs.add() method, you must connect to the primary of the replica set.

You can read more about it here: Reconfigure a Replica Set with Unavailable Members

If you have any doubts, please feel free to reach out to us.

Kushagra Kesav

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.