mrt:dbproxy

v0.0.6Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

DBProxy

Simple wrapper for adding multiple MONGO_URLs to your meteor app.

How to install?

  1. Install meteorite
  2. mrt add dbproxy

How to use?

Meteor DBProxy using MongoInternals to proxy collections from other databases into your app and surface all the reactive functionality of the collection as if it were local (via MONGO_URL). This package works on the client AND server.

Put this in your /lib folder (e.g., /lib/proxyDb.js).

var proxyDB;
Meteor.startup(function() {

	var _opts = {
		collections: [
			{ db: "collectionNameInMongo", name: "CollectionNameInMeteor" }
		]
		, bindables: ["find", "findOne"] //specify all the operators you want to bind
	};

	//when this runs on the server, you must provide the MONGO_URL to the proxy database
	//as well as an (optional) oplog mongo url
	if (Meteor.isServer) {
		_.extend(_opts, { 
			mongoUrl: process.env.OTHER_MONGO_URL
			, oplogUrl: process.env.OTHER_MONGO_OPLOG_URL 
		});
	}

	proxyDB = new MeteorDBProxy(_opts);
});

Now, you should be able to do this on either the client or the server:

proxyDB.CollectionNameInMeteor.find({...});

proxyDB.CollectionNameInMeteor.find({...}).observe({...});

Remember, however, that the client collections may be empty if you do not publish first, so ensure you have pub/sub wired up:

//on the server
Meteor.publish("publicationName", function() {
	return proxyDB.CollectionNameInMeteor.find();
});

//on the client
Meteor.subscribe("publicationName");

//once this sub is `ready` you ought to be able to do this on the client:
proxyDB.CollectionNameInMeteor.find({..});

###A couple notes:

  • The name is an optional param when passing in the collections. If this is omitted, the db will be used instead.
  • The oplogUrl is optional
  • The bindables option lets you specify what operations you want to run against the proxy; for a complete list, check out the source here

Thanks to Matt Debergalis for filling me in on this pattern.