0

I have two MongoDB running in two different servers connected via LAN. I want to replicate records from few collections from server 1 to collections in server 2. Is there any way to do it. Below is the pictorial representation of what I want to achieve.

enter image description here

Following are the methods I consider using.

  1. MongoDB replication - But it replicates all collections. Is selective replication possible in MongoDB ??
  2. Oplog watcher APIs - Please suggest some reliable java APIs

Is there any other way to do this ? and what is the best way of doing it ?

Maria
  • 1,161
  • 3
  • 12
  • 21

1 Answers1

1

MongoDB does not yet support selective replication and it sounds as though you are not actually looking for selective replication but more for selective copying since replication ensures certain rules of using that server.

I am not sure what you mean by a oplog watcher API but it is easy enough to read the oplog over time by just querying it:

> use local
> db.oplog.rs.find()

( http://docs.mongodb.org/manual/reference/local-database/ )

and then storing the latest timestamp of the record you have copied within a script you make.

You can also use a tailable cursor here on the oplog to effectiely listen (pub/sub) to changes and copy them over to your other server.

Sammaye
  • 43,242
  • 7
  • 104
  • 146
  • Giving `db.local.oplog.find()` does not return me anything and running `db.oplog.stats()` gives error `{ "ok" : 0, "errmsg" : "ns not found" }`. I have started server with `--master` – Maria Mar 06 '14 at 10:06
  • @Sandra Oops sorry, it is actually a database itself: http://docs.mongodb.org/manual/reference/local-database/ – Sammaye Mar 06 '14 at 10:07
  • @Sandra also --master is master slave replication which is deprecated you want to use replica sets – Sammaye Mar 06 '14 at 10:09
  • I don want to use replica sets. I just want to enable oplog in the first server – Maria Mar 06 '14 at 10:36
  • 1
    @Sandra then you just make a one member replica set – Sammaye Mar 06 '14 at 10:45
  • @Sandra it does appear that master slave replication uses an oplog afterall, it is just a different name – Sammaye Mar 06 '14 at 11:20
  • Thanks so much. I got it working with --replSet. Able to see oplog . But my question is not answered yet :) – Maria Mar 06 '14 at 13:11
  • @Sandra indeed my knowledge of Java isn't enough to give you the full answer :( – Sammaye Mar 06 '14 at 13:39
  • But how do you say '--master' is depricated. From which version ? – Maria Mar 06 '14 at 15:18
  • @Sandra it's not deprecated in the sense it wil be removed but if you look at the warning at the top: http://docs.mongodb.org/manual/core/master-slave/ it was deprecated for usage in about...hmm I think replica sets came out in 1.6 I think – Sammaye Mar 06 '14 at 15:33