Syncing live data between external database and meteor database

Hi

I have a database from IBM Bluemix, stored in Mongolab, which consist of data collected from sensors. I would like to display those data on my meteor app, and was thinking if there is any method to do that, without losing the reactivity of meteor mocal database, i.e. when there is a new data in the bluemix mongodb, my app will be updated with the latest data.

You can use a remote mongo collection like this. I just checked out some code on meteor’s mongo package and found this.

  1. Create a new MongoInternals.RemoteCollectionDriver for your external db
  2. Create a Mongo.Collection and give your driver in options.

I wrote a small POC meteor app and tried this and it works just like a local mongo collection.

if (Meteor.isClient) {
  var RCollection = new Meteor.Collection('remote_collection');

  Template.hello.helpers({
    items: function () {
      return RCollection.find({});
    }
  });
}

if (Meteor.isServer) {
  // replace these with your external mongo info
  var mongoUrl = 'mongodb://127.0.0.1:3001/meteor';
  var oplogUrl = 'mongodb://127.0.0.1:3001/local';

  var remoteDriver = new MongoInternals.RemoteCollectionDriver(mongoUrl, {
    oplogUrl: oplogUrl,
  });

  var remoteCollection = new Mongo.Collection('remote_collection', {
    _driver: remoteDriver,
  });
}
1 Like

Hi @mnmtanish!

Thanks for your reply! will try that out!