- How to set up a local mongodb with mirror on mongolab (propagate all writes from local to mongolab, so they are always synchronized – I don’t care about atomic, just that it syncs in a reasonable time frame)
- How to use mongolab as a fallback if local server stops working (Ruby/Rails, mongo driver and mongoid).
Background: I used to have a local mongo server but it kept crashing occasionally and all my apps stopped working + I had to “repair” the DB to restart it. Then I switched to mongolab which I am very satisfied with, but it’s generating a lot of traffic which I’d like to avoid by having a local “cache”, but without having to worry about my local cache crashing causing all my apps to stop working. The DBs are relatively small so size is not an issue. I’m not trying to eliminate the traffic overhead of communicating to mongolab, just lower it a bit.
I’m assuming you don’t want to have the mongolab instance just be part of a replica set (or perhaps that is not offered). The easiest way would be to add the remote mongod instance as a hidden member (priority 0) and just have it replicate data from your local instance.
An alternative immediate solution you could use is
mongooplogwhich can be used to poll the oplog on one server and then apply it to another. Essentially replication on demand (you would need to seed one instance appropriately etc. and would need to manage any failures). More information here:http://docs.mongodb.org/manual/reference/mongooplog/
The last option would be to write something yourself using a tailable cursor in your language of choice to feed the oplog data into the remote instance.