Skip to content

Update packages #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
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

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
32 changes: 25 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};
Expand All @@ -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);
});
};
Expand Down Expand Up @@ -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
//
Expand All @@ -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);
}
};
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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') {
Expand Down
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.0.1",
"mongodb": "^3.1.0",
"sharedb": "^1.0.0-beta",
"sharedb-mingo-memory": "^1.0.1"
},
"scripts": {
"test": "node_modules/.bin/mocha",
Expand Down
10 changes: 5 additions & 5 deletions test/test_mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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();
});
Expand Down