Put Mongo internal stuff onto MongoInternals.

This commit is contained in:
David Glasser
2013-07-29 17:11:42 -07:00
parent 0c7954b476
commit 97eca2bd7c
5 changed files with 21 additions and 16 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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));
};

View File

@@ -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');

View File

@@ -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);
});