Replica set with two data center

Hi students !

I read this in the great MongoDB documentation :

Three-member Replica Set
For example, for a three-member replica set, some possible distributions of members include:
Two data centers: two members to Data Center 1 and one member to Data Center 2. If one of the members of the replica set is an arbiter, distribute the arbiter to Data Center 1 with a data-bearing member.
- If Data Center 1 goes down, the replica set becomes read-only.
- If Data Center 2 goes down, the replica set remains writeable as the members in Data Center 1 can hold an election.

If Data Center 1 goes down
Because of the quorum, the node on Data Center 2 can’t become a primary. So it remains a secondary. We can access this node by direct connection, but I thought that the replica set would be unavailable.

But here, the documentation says the replica set is read-only, so it is available.

How is it possible ?

Thank you for your answers !

This is what I think the documentation is saying:

If Data Center 1 goes down, the entire replica set becomes read-only because now the only available member is a secondary in Data Center 2. Because that one available member in Data Center 2 is secondary, it cannot accept writes like a primary would be able to. Additionally, because the other two members in the replica set are located in Data Center 1, and that Data Center is down, there are not enough members to vote to elect a new primary. So the topology of the replica set never gets updated with a new primary member that can accept writes.

Therefore, the replica set is read-only because there is only one functioning member and that member can only do read operations. So yes, the member in Data Center 2 is “available”, but only for read-operations. It is not available in the sense that it can make the replica set usable for normal database operations.

1 Like

Thank you @Jennifer_45288 for your answer :slight_smile:

I guess you’re right ; they probably means this by saying “the replica set becomes read-only”

Thank you, and have a good day !

My 2 cents for clarity…

Yes the replica set becomes unavailable in the sense that connections that use the replica set name as part of the connection string will fail because there’s no Primary. In essence, you will no longer be connected to a replica set. Only direct connections to a secondary node, i.e. connection strings without the name of the replica set and host+port pointing to that available node, will succeed.

Secondly, the documentation fails to mention how Read Preference will affect reads. A Read Preference of Primary will fail, but all other preferences (i.e. primaryPreferred, secondary, secondaryPreferred, nearest) will work. And as the default is primary, you must specify the afore-mentioned for you to be able to read from a Secondary.


Thank you @007_jb :slight_smile:
I didn’t think about the fact that Read Preference can allow us to read our data from the secondary.
In this case where only Data Center 2 is available, this is a good solution.

So it’s perfectly clear now, thant you !