Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongodb single DB replication

I've a working MongoDB "replica set" made up by 3 servers. It is storing two DBs, I wonder if is it possible to replicate only one of the DBs without running more than one mongoDB instance(one per DB).

Here is a sketch of the "problem"

      Server1   Server2   Server3
DB1      X         X         X
DB2      X         X

X stands for Server where DBs have to be replicated in.

thank

like image 655
Lopoc Avatar asked Mar 14 '11 14:03

Lopoc


2 Answers

I don't believe it is possible.

Unlike sharding, where you specify down to the collection level what gets sharded, with replica sets you're defining that a given MongoDB instance is part of a replica set. As only one node in a replica set can be the master at any given time, based on the scenario you are talking about, then there would be a problem if e.g. Server1 went down and Server3 was promoted to master - as DB2 would then not be able to be written to.

like image 174
AdaTheDev Avatar answered Oct 02 '22 22:10

AdaTheDev


I had a simliar problem and found a quite easy solution in javascript to be executed in a mongo-shell.

Sourcecode available here: http://www.suenkel.de/blog/2012/02/mongodb-replicate-one-database-or-collection/

With opening a tailable cursor on the oplog of the master server each operation could be applied to another server (of course you can filter by the namespace of the collections or even the databases...)

like image 36
Christian Suenkel Avatar answered Oct 02 '22 22:10

Christian Suenkel