Skip to content
Merged
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
12 changes: 1 addition & 11 deletions lib/mongo-milestone-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ class MongoMilestoneDB extends MilestoneDB {
}

_db() {
return this._client().then(client => (MongoMilestoneDB._isLegacyMongoClient(client)
? client
: client.db()));
return this._client().then(client => client.db());
}

_collection(collectionName) {
Expand Down Expand Up @@ -253,14 +251,6 @@ class MongoMilestoneDB extends MilestoneDB {
if (typeof object !== 'object') return object;
return Object.assign({}, object);
}

static _isLegacyMongoClient(client) {
// mongodb 2.x connect returns a DB object that also implements the
// functionality of a client, such as `close()`. mongodb 3.x connect
// returns a Client without the `collection()` method
return typeof client.collection === 'function'
&& typeof client.close === 'function';
}
}

class InvalidCollectionNameError extends Error {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
"description": "MongoDB milestone snapshot database adapter for ShareDB",
"main": "lib/index.js",
"dependencies": {
"mongodb": "^2.2.36 || ^3.0.0 || ^4.0.0 || ^5.0.0",
"mongodb": "^3.0.0 || ^4.0.0 || ^5.0.0",
"sharedb": "^1.0.0 || ^2.0.0 || ^3.0.0"
},
"devDependencies": {
"chai": "^4.2.0",
"coveralls": "^3.1.0",
"eslint": "^7.14.0",
"mocha": "^8.2.1",
"mongodb2": "npm:mongodb@^2.2.36",
"mongodb3": "npm:mongodb@^3.0.0",
"mongodb4": "npm:mongodb@^4.0.0",
"mongodb5": "npm:mongodb@^5.0.0",
Expand Down
14 changes: 3 additions & 11 deletions test/mongo-milestone-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const mongodbRequire = require('../lib/mongodb');
const MONGO_URL = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test';

[
'mongodb2',
'mongodb3',
'mongodb4',
'mongodb5',
Expand All @@ -17,7 +16,6 @@ const MONGO_URL = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test'
function create(options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}

let db;
Expand All @@ -35,9 +33,7 @@ const MONGO_URL = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test'
connect(MONGO_URL)
.then((mongoConnection) => {
mongo = mongoConnection;
return MongoMilestoneDB._isLegacyMongoClient(mongo)
? mongo.dropDatabase()
: mongo.db().dropDatabase();
return mongo.db().dropDatabase();
})
.then(() => {
shareDbCallback(null, mongo);
Expand Down Expand Up @@ -65,9 +61,7 @@ const MONGO_URL = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test'
create((error, createdDb, createdMongo) => {
if (error) return done(error);
db = createdDb;
mongo = MongoMilestoneDB._isLegacyMongoClient(createdMongo)
? createdMongo
: createdMongo.db();
mongo = createdMongo.db();
done();
});
});
Expand Down Expand Up @@ -151,9 +145,7 @@ const MONGO_URL = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test'
create(options, (error, createdDb, createdMongo) => {
if (error) return done(error);
db = createdDb;
mongo = MongoMilestoneDB._isLegacyMongoClient(createdMongo)
? createdMongo
: createdMongo.db();
mongo = createdMongo.db();
done();
});
});
Expand Down