From 1c6ac5eb18777e8c9a09e661d5b45d50550188f7 Mon Sep 17 00:00:00 2001 From: David Charbonnier Date: Wed, 27 Jun 2018 18:40:36 +0200 Subject: [PATCH 1/3] clean mongo and node versions --- .travis.yml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4248e13b..ddcb0f18 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,20 +1,17 @@ language: node_js node_js: - - 7 - - 6 - - 4 - - 0.10 + - "6" + - "8" + - "10" services: - docker env: - - MONGODB_VERSION="2.4" - MONGODB_VERSION="2.6" - - MONGODB_VERSION="3.0" - - MONGODB_VERSION="3.2" - - MONGODB_VERSION="3.4" + - MONGODB_VERSION="3.6" + - MONGODB_VERSION="4.0" before_install: - docker run -d -p 127.0.0.1:27017:27017 mongo:$MONGODB_VERSION @@ -22,8 +19,9 @@ before_install: before_script: - until nc -z localhost 27017; do echo Waiting for MongoDB; sleep 1; done -# Run twice due to Mongo flakiness -script: "npm run test-cover || npm run test-cover" +script: + - npm run test-cover # Send coverage data to Coveralls -after_script: "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" +after_script: + - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js From 59406c59bd279a000f6a358bd418322b82f0b78f Mon Sep 17 00:00:00 2001 From: dcharbonnier Date: Thu, 28 Jun 2018 08:18:57 +0200 Subject: [PATCH 2/3] Upgrade packages * upgrade packages * fix mongo url deprecation --- index.js | 32 +++++++++++++++++++++++++------- package.json | 16 ++++++++++------ test/test_mongo.js | 10 +++++----- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 2719c1ad..4d417086 100644 --- a/index.js +++ b/index.js @@ -70,7 +70,7 @@ ShareDbMongo.prototype.getCollection = function(collectionName, callback) { // Gotcha: calls back sync if connected or async if not this.getDbs(function(err, mongo) { if (err) return callback(err); - var collection = mongo.collection(collectionName); + var collection = mongo.db().collection(collectionName); return callback(null, collection); }); }; @@ -82,7 +82,7 @@ ShareDbMongo.prototype._getCollectionPoll = function(collectionName, callback) { // Gotcha: calls back sync if connected or async if not this.getDbs(function(err, mongo, mongoPoll) { if (err) return callback(err); - var collection = (mongoPoll || mongo).collection(collectionName); + var collection = (mongoPoll || mongo).db().collection(collectionName); return callback(null, collection); }); }; @@ -118,6 +118,14 @@ ShareDbMongo.prototype._flushPendingConnect = function() { } }; +ShareDbMongo.prototype._mongodbOptions = function(options) { + if(options instanceof Object) { + return Object.assign(Object.assign({}, options.mongoOptions), { useNewUrlParser: true }) + } else { + return { useNewUrlParser: true }; + } +} + ShareDbMongo.prototype._connect = function(mongo, options) { // Create the mongo connection client connections if needed // @@ -131,10 +139,10 @@ ShareDbMongo.prototype._connect = function(mongo, options) { } else { tasks = { mongo: function(parallelCb) { - mongodb.connect(mongo, options.mongoOptions, parallelCb); + mongodb.connect(mongo, self._mongodbOptions(options.mongoOptions), parallelCb); }, mongoPoll: function(parallelCb) { - mongodb.connect(options.mongoPoll, options.mongoPollOptions, parallelCb); + mongodb.connect(options.mongoPoll, self._mongodbOptions(options.mongoPollOptions), parallelCb); } }; } @@ -155,7 +163,7 @@ ShareDbMongo.prototype._connect = function(mongo, options) { mongo(finish); return; } - mongodb.connect(mongo, options, finish); + mongodb.connect(mongo, this._mongodbOptions(options), finish); }; ShareDbMongo.prototype.close = function(callback) { @@ -306,7 +314,7 @@ ShareDbMongo.prototype.getOpCollection = function(collectionName, callback) { this.getDbs(function(err, mongo) { if (err) return callback(err); var name = self.getOplogCollectionName(collectionName); - var collection = mongo.collection(name); + var collection = mongo.db().collection(name); // Given the potential problems with creating indexes on the fly, it might // be preferrable to disable automatic creation if (self.disableIndexCreation) { @@ -1274,7 +1282,17 @@ var collectionOperationsMap = { collection.distinct(value.field, query, cb); }, '$aggregate': function(collection, query, value, cb) { - collection.aggregate(value, cb); + collection.aggregate(value, function(err, cursor) { + if(err) { + return cb(err); + } + cursor.toArray(function (err, res) { + if(err) { + return cb(err); + } + return cb(null, res); + }); + }); }, '$mapReduce': function(collection, query, value, cb) { if (typeof value !== 'object') { diff --git a/package.json b/package.json index 951d3ce5..dac2ed37 100644 --- a/package.json +++ b/package.json @@ -4,16 +4,20 @@ "description": "MongoDB database adapter for ShareDB", "main": "index.js", "dependencies": { - "async": "^1.4.2", - "mongodb": "^2.1.2", + "async": "^2.6.1" + }, + "peerDependencies": { + "mongodb": "^3.1.0", "sharedb": "^1.0.0-beta" }, "devDependencies": { - "coveralls": "^2.11.8", + "coveralls": "^3.0.1", "expect.js": "^0.3.1", - "istanbul": "^0.4.2", - "mocha": "^2.3.3", - "sharedb-mingo-memory": "^1.0.0-beta" + "istanbul": "^0.4.5", + "mocha": "^5.2.0", + "mongodb": "^3.1.0", + "sharedb": "^1.0.0-beta", + "sharedb-mingo-memory": "^1.0.1" }, "scripts": { "test": "node_modules/.bin/mocha", diff --git a/test/test_mongo.js b/test/test_mongo.js index d5ee6f67..3b538981 100644 --- a/test/test_mongo.js +++ b/test/test_mongo.js @@ -7,9 +7,9 @@ var mongoUrl = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test'; function create(callback) { var db = ShareDbMongo({mongo: function(shareDbCallback) { - mongodb.connect(mongoUrl, function(err, mongo) { + mongodb.connect(mongoUrl, { useNewUrlParser: true }, function(err, mongo) { if (err) return callback(err); - mongo.dropDatabase(function(err) { + mongo.db().dropDatabase(function(err) { if (err) return callback(err); shareDbCallback(null, mongo); callback(null, db, mongo); @@ -40,7 +40,7 @@ describe('mongo db', function() { var mongo = this.mongo; this.db.commit('testcollection', 'foo', {v: 0, create: {}}, {}, null, function(err) { if (err) return done(err); - mongo.collection('o_testcollection').indexInformation(function(err, indexes) { + mongo.db().collection('o_testcollection').indexInformation(function(err, indexes) { if (err) return done(err); // Index for getting document(s) ops expect(indexes['d_1_v_1']).ok(); @@ -53,7 +53,7 @@ describe('mongo db', function() { it('respects unique indexes', function(done) { var db = this.db; - this.mongo.collection('testcollection').createIndex({x: 1}, {unique: true}, function(err) { + this.mongo.db().collection('testcollection').createIndex({x: 1}, {unique: true}, function(err) { if (err) return done(err); db.commit('testcollection', 'foo', {v: 0, create: {}}, {v: 1, data: {x: 7}}, null, function(err, succeeded) { if (err) return done(err); @@ -341,7 +341,7 @@ describe('mongo db connection', function() { // logic. this.db.getDbs(function(err, mongo, mongoPoll) { if (err) return done(err); - mongo.dropDatabase(function(err) { + mongo.db().dropDatabase(function(err) { if (err) return done(err); done(); }); From f0aea0f11eb3a210feecb90cb6b993f6e330dbda Mon Sep 17 00:00:00 2001 From: Greg Kubisa Date: Thu, 19 Jul 2018 14:48:09 +0200 Subject: [PATCH 3/3] Downgrade mocha (temp solution to pass tests) See https://github.com/mochajs/mocha/releases/tag/v5.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dac2ed37..a413cc3b 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "coveralls": "^3.0.1", "expect.js": "^0.3.1", "istanbul": "^0.4.5", - "mocha": "^5.2.0", + "mocha": "5.0.1", "mongodb": "^3.1.0", "sharedb": "^1.0.0-beta", "sharedb-mingo-memory": "^1.0.1"