0

I have a mongodb replica set (1 primary, 2 secondary instances): vm1, vm2, vm3.

I had a need for a second replica set so I created a copy of the above vms: vm4, vm5, vm6.

After booting up vms[4-6] and connecting to them, obviously, when checking the members of the cluster with rs.status() , I can still see vm[1-3] listed as members of the cluster there instead of the new vms. My question is:

Can I use rs.reconfig() to update at once all the members in the second triad so that I have 2 independent clusters while leaving the data intact? The expected outcome is to have two independent clusters:

  • cluster1: vm1, vm2, vm3
  • cluster2: vm4, vm5, vm6

that (initially) have the same data and function independently.

Is my approach correct or should I be doing this differently? Should I just export data from the initial cluster, create a fresh replica set and then import data back to the new cluster?

0

1 Answer 1

0

The easiest way is to create empty instances of vm4, vm5, vm6. Start them and add them to your replica set with rs.add(). It will trigger an initial sync and after a short time you will have everything properly replicated.

Or do you ask for an independent second replica set of 3 members? In this case, copy data just from one secondary to one of your vm in cluster 2

Connect to the new vm and drop the local database. Then you can use rs.init() and rs.add() again.

Follow this instruction: Restore a Replica Set from MongoDB Backups

1
  • Hi Wernfried, sorry if my question was unclear, I was indeed referring to the second case(independent replica). I followed your instructions and everything worked like a charm. Thank you.
    – spk
    Commented Nov 22, 2021 at 18:02

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.