I've got the following layout Picture Cluster

RZ West is my first data center A and RZ Ost my second data center B. As you can see one secondary database of each cluster is available in the other data center.

Is it possible to read data out of Secondary 2 OST (B) and add it to the master database Primary WEST (A) automatically?

To understand the question this solved question could be helpful https://stackoverflow.com/questions/22988773/mongodb-multiple-masters-in-replicaset

Thank you very much in advance

Greetings, Daniel

2 Answers 2


From your question, I take it that you wish to write only to the local primary, but read from either replica set.

The solution would be a sharded cluster formed from your two replica sets with their current setup. You can then setup a new collection which includes shard tagging. You should set this up so that the data which was in DCA will stay in DCA, and the data in DCB will remain in DCB. If you setup in this manner your writes from each application will be directed only to the "local" Primary (which receives writes) for each system are located in the same DC.

When you go to read data you can use the nearest read preference to read from the closest member, which given your setup will always be in the Local DC. You will need to setup a MongoS in each DC and this would be the point you connect to for your application.

  • So you mean that it's set up like this, right? If i connect my applications to the local mongos instance they will read data out of mongos. As seen in the picture I've got a secondary of each replica in the other DC. When mongos is reading from the closest member will it be reading from each replica set or only from replica set A (for example)?
    – DanielH
    Commented Apr 16, 2014 at 7:24
  • I am suggesting a sharded cluster like that, yes (you need to add config servers as they are a requirement for sharding). MongoS is a router, it doesn't contain any data itself, but reads and returns data from the shards (which would be your 2 replica sets). If you specify a read preference of nearest the MongoS would direct its reads to the closest (by ping) member of the replica set that contains the relevant data for the query. This way, you could query both sets on one connection and one collection without leaving the local DC.
    – daveh
    Commented Apr 16, 2014 at 7:30
  • Thank you very much for this explanation. I will try it and come back here again, if I got any problems
    – DanielH
    Commented Apr 16, 2014 at 7:34

If it's not possible to do it automatically, can it be done manually? So only entries which are not present in the primary database A will be inserted out of one secondary of database B ?

Little Example: In A we got: 1,2,3 In B we got: 5,6,7

What I want is to add 5,6,7 from database B into database A and vice versa, so it looks like this at the end:

A: 1,2,3,5,6,7

B: 5,6,7,1,2,3

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.