How to replicate between On-Premises and Azure in Mongodb

All we need is an easy explanation of the problem, so here it is.

I have three 3 node cluster on-premises ( 1 Primary and 2 Secondary ). I have same 3 node cluster in AZURE ( 1 Primary and 2 Secondary ) with same version and data but with different FQDN in azure. How shall I connect mongodb replica set in azure to mongodb replica set in on-premises so that they can start replicating the data. Later I would like to switch off on-premises mongodb and move finally to azure. My question is:

  1. What would be my architecture? Shall I make all the 3 members in azure secondary with hidden:true , priority:0 and add/connect all of them to on-premises?
  2. What configuration changes do I need to make in mongod.conf file both in on-prem and in azure so that communication can be established between the node?

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Basically, you add those three nodes as secondary to your current on-premise replica set. (rs.add(FQDN))
Not necessary to be hidden, but set priority lower than nodes at the premises, to prevent primary to moving there before you want to do so.

What comes to the communication, check that firewalls are open so that every node can reach each other and your Azure nodes are not "open to the world".

When you want to move primary there, modify rs.conf() so that (one of) Azure nodes have the highest priority, and two azure nodes have the second highest priority. Then "remove" those on-premise nodes from the setup. (rs.remove(FQDN))

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply