Skip to content

Commit 59406c5

Browse files
dcharbonniergkubisa
authored andcommitted
Upgrade packages
* upgrade packages * fix mongo url deprecation
1 parent 1c6ac5e commit 59406c5

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

index.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ ShareDbMongo.prototype.getCollection = function(collectionName, callback) {
7070
// Gotcha: calls back sync if connected or async if not
7171
this.getDbs(function(err, mongo) {
7272
if (err) return callback(err);
73-
var collection = mongo.collection(collectionName);
73+
var collection = mongo.db().collection(collectionName);
7474
return callback(null, collection);
7575
});
7676
};
@@ -82,7 +82,7 @@ ShareDbMongo.prototype._getCollectionPoll = function(collectionName, callback) {
8282
// Gotcha: calls back sync if connected or async if not
8383
this.getDbs(function(err, mongo, mongoPoll) {
8484
if (err) return callback(err);
85-
var collection = (mongoPoll || mongo).collection(collectionName);
85+
var collection = (mongoPoll || mongo).db().collection(collectionName);
8686
return callback(null, collection);
8787
});
8888
};
@@ -118,6 +118,14 @@ ShareDbMongo.prototype._flushPendingConnect = function() {
118118
}
119119
};
120120

121+
ShareDbMongo.prototype._mongodbOptions = function(options) {
122+
if(options instanceof Object) {
123+
return Object.assign(Object.assign({}, options.mongoOptions), { useNewUrlParser: true })
124+
} else {
125+
return { useNewUrlParser: true };
126+
}
127+
}
128+
121129
ShareDbMongo.prototype._connect = function(mongo, options) {
122130
// Create the mongo connection client connections if needed
123131
//
@@ -131,10 +139,10 @@ ShareDbMongo.prototype._connect = function(mongo, options) {
131139
} else {
132140
tasks = {
133141
mongo: function(parallelCb) {
134-
mongodb.connect(mongo, options.mongoOptions, parallelCb);
142+
mongodb.connect(mongo, self._mongodbOptions(options.mongoOptions), parallelCb);
135143
},
136144
mongoPoll: function(parallelCb) {
137-
mongodb.connect(options.mongoPoll, options.mongoPollOptions, parallelCb);
145+
mongodb.connect(options.mongoPoll, self._mongodbOptions(options.mongoPollOptions), parallelCb);
138146
}
139147
};
140148
}
@@ -155,7 +163,7 @@ ShareDbMongo.prototype._connect = function(mongo, options) {
155163
mongo(finish);
156164
return;
157165
}
158-
mongodb.connect(mongo, options, finish);
166+
mongodb.connect(mongo, this._mongodbOptions(options), finish);
159167
};
160168

161169
ShareDbMongo.prototype.close = function(callback) {
@@ -306,7 +314,7 @@ ShareDbMongo.prototype.getOpCollection = function(collectionName, callback) {
306314
this.getDbs(function(err, mongo) {
307315
if (err) return callback(err);
308316
var name = self.getOplogCollectionName(collectionName);
309-
var collection = mongo.collection(name);
317+
var collection = mongo.db().collection(name);
310318
// Given the potential problems with creating indexes on the fly, it might
311319
// be preferrable to disable automatic creation
312320
if (self.disableIndexCreation) {
@@ -1274,7 +1282,17 @@ var collectionOperationsMap = {
12741282
collection.distinct(value.field, query, cb);
12751283
},
12761284
'$aggregate': function(collection, query, value, cb) {
1277-
collection.aggregate(value, cb);
1285+
collection.aggregate(value, function(err, cursor) {
1286+
if(err) {
1287+
return cb(err);
1288+
}
1289+
cursor.toArray(function (err, res) {
1290+
if(err) {
1291+
return cb(err);
1292+
}
1293+
return cb(null, res);
1294+
});
1295+
});
12781296
},
12791297
'$mapReduce': function(collection, query, value, cb) {
12801298
if (typeof value !== 'object') {

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@
44
"description": "MongoDB database adapter for ShareDB",
55
"main": "index.js",
66
"dependencies": {
7-
"async": "^1.4.2",
8-
"mongodb": "^2.1.2",
7+
"async": "^2.6.1"
8+
},
9+
"peerDependencies": {
10+
"mongodb": "^3.1.0",
911
"sharedb": "^1.0.0-beta"
1012
},
1113
"devDependencies": {
12-
"coveralls": "^2.11.8",
14+
"coveralls": "^3.0.1",
1315
"expect.js": "^0.3.1",
14-
"istanbul": "^0.4.2",
15-
"mocha": "^2.3.3",
16-
"sharedb-mingo-memory": "^1.0.0-beta"
16+
"istanbul": "^0.4.5",
17+
"mocha": "^5.2.0",
18+
"mongodb": "^3.1.0",
19+
"sharedb": "^1.0.0-beta",
20+
"sharedb-mingo-memory": "^1.0.1"
1721
},
1822
"scripts": {
1923
"test": "node_modules/.bin/mocha",

test/test_mongo.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ var mongoUrl = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test';
77

88
function create(callback) {
99
var db = ShareDbMongo({mongo: function(shareDbCallback) {
10-
mongodb.connect(mongoUrl, function(err, mongo) {
10+
mongodb.connect(mongoUrl, { useNewUrlParser: true }, function(err, mongo) {
1111
if (err) return callback(err);
12-
mongo.dropDatabase(function(err) {
12+
mongo.db().dropDatabase(function(err) {
1313
if (err) return callback(err);
1414
shareDbCallback(null, mongo);
1515
callback(null, db, mongo);
@@ -40,7 +40,7 @@ describe('mongo db', function() {
4040
var mongo = this.mongo;
4141
this.db.commit('testcollection', 'foo', {v: 0, create: {}}, {}, null, function(err) {
4242
if (err) return done(err);
43-
mongo.collection('o_testcollection').indexInformation(function(err, indexes) {
43+
mongo.db().collection('o_testcollection').indexInformation(function(err, indexes) {
4444
if (err) return done(err);
4545
// Index for getting document(s) ops
4646
expect(indexes['d_1_v_1']).ok();
@@ -53,7 +53,7 @@ describe('mongo db', function() {
5353

5454
it('respects unique indexes', function(done) {
5555
var db = this.db;
56-
this.mongo.collection('testcollection').createIndex({x: 1}, {unique: true}, function(err) {
56+
this.mongo.db().collection('testcollection').createIndex({x: 1}, {unique: true}, function(err) {
5757
if (err) return done(err);
5858
db.commit('testcollection', 'foo', {v: 0, create: {}}, {v: 1, data: {x: 7}}, null, function(err, succeeded) {
5959
if (err) return done(err);
@@ -341,7 +341,7 @@ describe('mongo db connection', function() {
341341
// logic.
342342
this.db.getDbs(function(err, mongo, mongoPoll) {
343343
if (err) return done(err);
344-
mongo.dropDatabase(function(err) {
344+
mongo.db().dropDatabase(function(err) {
345345
if (err) return done(err);
346346
done();
347347
});

0 commit comments

Comments
 (0)