From 97eca2bd7c154d5c8c8f6ceab3d74b68578abb74 Mon Sep 17 00:00:00 2001 From: David Glasser Date: Mon, 29 Jul 2013 17:11:42 -0700 Subject: [PATCH] Put Mongo internal stuff onto MongoInternals. --- packages/mongo-livedata/collection.js | 8 +++++--- packages/mongo-livedata/mongo_driver.js | 12 ++++++------ packages/mongo-livedata/observe_changes_tests.js | 2 +- packages/mongo-livedata/package.js | 7 +++++-- packages/mongo-livedata/remote_collection_driver.js | 8 ++++---- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/packages/mongo-livedata/collection.js b/packages/mongo-livedata/collection.js index b66b298587..1cea1d650e 100644 --- a/packages/mongo-livedata/collection.js +++ b/packages/mongo-livedata/collection.js @@ -61,10 +61,12 @@ Meteor.Collection = function (name, options) { if (!options._driver) { if (name && self._connection === Meteor.server && - typeof getRemoteCollectionDriver !== "undefined") - options._driver = getRemoteCollectionDriver(); - else + typeof MongoInternals !== "undefined" && + MongoInternals.defaultRemoteCollectionDriver) { + options._driver = MongoInternals.defaultRemoteCollectionDriver(); + } else { options._driver = LocalCollectionDriver; + } } self._collection = options._driver.open(name, self._connection); diff --git a/packages/mongo-livedata/mongo_driver.js b/packages/mongo-livedata/mongo_driver.js index b83108aaea..e3fcf835d9 100644 --- a/packages/mongo-livedata/mongo_driver.js +++ b/packages/mongo-livedata/mongo_driver.js @@ -12,6 +12,8 @@ var MongoDB = Npm.require('mongodb'); var Fiber = Npm.require('fibers'); var Future = Npm.require(path.join('fibers', 'future')); +MongoInternals = {}; + var replaceNames = function (filter, thing) { if (typeof thing === "object") { if (_.isArray(thing)) { @@ -122,10 +124,6 @@ MongoConnection = function (url) { }); }; -// Some apps want to use this directly. Maybe they shouldn't, but let's not -// break them yet. -Meteor._Mongo = MongoConnection; - MongoConnection.prototype.close = function() { var self = this; // Use Future.wrap so that errors get thrown. This happens to @@ -991,7 +989,7 @@ _.extend(LiveResultsSet.prototype, { // - If you disconnect and reconnect from Mongo, it will essentially restart // the query, which will lead to duplicate results. This is pretty bad, // but if you include a field called 'ts' which is inserted as -// new MongoConnection.MongoTimestamp(0, 0) (which is initialized to the +// new MongoInternals.MongoTimestamp(0, 0) (which is initialized to the // current Mongo-style timestamp), we'll be able to find the place to // restart properly. (This field is specifically understood by Mongo with an // optimization which allows it to find the right place to start without @@ -1081,4 +1079,6 @@ MongoConnection.prototype._observeChangesTailable = function ( // XXX We probably need to find a better way to expose this. Right now // it's only used by tests, but in fact you need it in normal // operation to interact with capped collections (eg, Galaxy uses it). -MongoConnection.MongoTimestamp = MongoDB.Timestamp; +MongoInternals.MongoTimestamp = MongoDB.Timestamp; + +MongoInternals.Connection = MongoConnection; diff --git a/packages/mongo-livedata/observe_changes_tests.js b/packages/mongo-livedata/observe_changes_tests.js index cf3e514e7d..94efe37af8 100644 --- a/packages/mongo-livedata/observe_changes_tests.js +++ b/packages/mongo-livedata/observe_changes_tests.js @@ -206,7 +206,7 @@ if (Meteor.isServer) { self.xs = []; self.expects = []; self.insert = function (fields) { - coll.insert(_.extend({ts: new Meteor._Mongo.MongoTimestamp(0, 0)}, + coll.insert(_.extend({ts: new MongoInternals.MongoTimestamp(0, 0)}, fields)); }; diff --git a/packages/mongo-livedata/package.js b/packages/mongo-livedata/package.js index f7e54f2d20..adc83c3862 100644 --- a/packages/mongo-livedata/package.js +++ b/packages/mongo-livedata/package.js @@ -26,10 +26,13 @@ Package.on_use(function (api) { // Allow us to detect 'autopublish', and publish collections if it's loaded. api.use('autopublish', 'server', {weak: true}); - // RemoteCollectionDriver gets its deployConfig from something that is (for - // questionable reasons) initialized by the webapp package. + // defaultRemoteCollectionDriver gets its deployConfig from something that is + // (for questionable reasons) initialized by the webapp package. api.use('webapp', 'server', {weak: true}); + // Stuff that should be exposed via a real API, but we haven't yet. + api.export('MongoInternals', 'server'); + api.add_files('mongo_driver.js', 'server'); api.add_files('local_collection_driver.js', ['client', 'server']); api.add_files('remote_collection_driver.js', 'server'); diff --git a/packages/mongo-livedata/remote_collection_driver.js b/packages/mongo-livedata/remote_collection_driver.js index 5996344faf..6ba05d0679 100644 --- a/packages/mongo-livedata/remote_collection_driver.js +++ b/packages/mongo-livedata/remote_collection_driver.js @@ -1,9 +1,9 @@ -var RemoteCollectionDriver = function (mongo_url) { +MongoInternals.RemoteCollectionDriver = function (mongo_url) { var self = this; self.mongo = new MongoConnection(mongo_url); }; -_.extend(RemoteCollectionDriver.prototype, { +_.extend(MongoInternals.RemoteCollectionDriver.prototype, { open: function (name) { var self = this; var ret = {}; @@ -21,7 +21,7 @@ _.extend(RemoteCollectionDriver.prototype, { // 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.) -getRemoteCollectionDriver = _.once(function () { +MongoInternals.defaultRemoteCollectionDriver = _.once(function () { // XXX kind of hacky var mongoUrl = ( typeof __meteor_bootstrap__ !== 'undefined' && @@ -31,5 +31,5 @@ getRemoteCollectionDriver = _.once(function () { if (! mongoUrl) throw new Error("MONGO_URL must be set in environment"); - return new RemoteCollectionDriver(mongoUrl); + return new MongoInternals.RemoteCollectionDriver(mongoUrl); });