How to create 2 node active-active MongoDB replicaset?

How to create 2 node active-active MongoDB replicaset?

Hi,

Can you elaborate a little bit more? What do you mean by 2-node active-active MDB replicaset?

All the best,

–Rodrigo

we need to setup DR of 2 node mongodb replicaset where both the nodes primary and secondary would be doing read and write

Hi,

In a replica set, only the Primary can handle reads and writes coming from the application. You can have the application sending read requests to the secondaries, but only the Primary can handle both reads and writes for the replica set.

All the best,

–Rodrigo

I have to set up DR of mongodb replica set in target region as active passive. Can you help me to know how the replication would be done from region1 to region2 and suppose all nodes in region1 go down then how the replica set in region2 will have latest data?

Hi Sonal,

I believe you have a few options to explore. Since, you’re talking about regions, I’m assuming you’re working on a Cloud environment.

If that is the case, have you consider using MongoDB ATLAS? In ATLAS you can have your MongoDB replicaset distribute across regions or even across different cloud providers by just flipping a switch while creating your cluster.

If that isn’t the case and you’re running on-premises, have you looked at mongosync?

All the best,

–Rodrigo

we are using aws regions and running with mongodb 4.2 community edition 3 node replica set on EC2 instance. Need to setup DR in region2 with active-passive setup. After inital sync from region1 to region2 how the replica set will elect primary in region2 if all nodes in region1 go down? Can you help me to clear this? How ill this work? Do Ineed to setup 3 node replica in DR region too and configure one node as hidden node?

Hi @Sonal_Sharma welcome to the community!

As @logwriter mentioned, there is no “active-active” setting for MongoDB replica set since a replica set uses the primary-secondary or leader-follower concept.

However there are other options to achieve this, detailed in the blog post Active-Active Application Architectures with MongoDB | MongoDB

Hope this helps!

Best regards
Kevin

1 Like

Hello,
This is for active -passive now with 2 different regions in AWS and if all nodes in region1 go down then how the replica set in region 2 will resume service in region2 and serve as primary?