Files
meteor/packages/mongo/remote_collection_driver.js
David Glasser 63a0076305 mongo: provide direct access to node driver db
Specifically, Mongo.Collection objects on the server now have
rawCollection and rawDatabase methods.

You can use MongoInternals.NpmModules.mongodb.version to tell what
version of the mongodb npm module is the backend for HTTP.call.  This
version may change incompatibly from version to version of Meteor; use
at your own risk.  (For example, we expect to upgrade from the 1.4.x
series to the 2.x series in the not-too-distant future.)

Fixes #3640.
2015-03-05 17:12:37 -08:00

40 lines
1.2 KiB
JavaScript

MongoInternals.RemoteCollectionDriver = function (
mongo_url, options) {
var self = this;
self.mongo = new MongoConnection(mongo_url, options);
};
_.extend(MongoInternals.RemoteCollectionDriver.prototype, {
open: function (name) {
var self = this;
var ret = {};
_.each(
['find', 'findOne', 'insert', 'update', 'upsert',
'remove', '_ensureIndex', '_dropIndex', '_createCappedCollection',
'dropCollection', 'rawCollection'],
function (m) {
ret[m] = _.bind(self.mongo[m], self.mongo, name);
});
return ret;
}
});
// Create the singleton RemoteCollectionDriver only on demand, so we
// only require Mongo configuration if it's actually used (eg, not if
// you're only trying to receive data from a remote DDP server.)
MongoInternals.defaultRemoteCollectionDriver = _.once(function () {
var connectionOptions = {};
var mongoUrl = process.env.MONGO_URL;
if (process.env.MONGO_OPLOG_URL) {
connectionOptions.oplogUrl = process.env.MONGO_OPLOG_URL;
}
if (! mongoUrl)
throw new Error("MONGO_URL must be set in environment");
return new MongoInternals.RemoteCollectionDriver(mongoUrl, connectionOptions);
});