Skip to content

Commit c742cad

Browse files
committed
💥 BREAKING: drop mongodb@2 support
The `mongodb@2` driver is not compatible with MongoDB v6. In order to add support for the latest database, we drop support for this old version of the `mongodb` driver.
1 parent cfc2291 commit c742cad

File tree

3 files changed

+5
-24
lines changed

3 files changed

+5
-24
lines changed

lib/mongo-milestone-db.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ class MongoMilestoneDB extends MilestoneDB {
160160
}
161161

162162
_db() {
163-
return this._client().then(client => (MongoMilestoneDB._isLegacyMongoClient(client)
164-
? client
165-
: client.db()));
163+
return this._client().then(client => client.db());
166164
}
167165

168166
_collection(collectionName) {
@@ -253,14 +251,6 @@ class MongoMilestoneDB extends MilestoneDB {
253251
if (typeof object !== 'object') return object;
254252
return Object.assign({}, object);
255253
}
256-
257-
static _isLegacyMongoClient(client) {
258-
// mongodb 2.x connect returns a DB object that also implements the
259-
// functionality of a client, such as `close()`. mongodb 3.x connect
260-
// returns a Client without the `collection()` method
261-
return typeof client.collection === 'function'
262-
&& typeof client.close === 'function';
263-
}
264254
}
265255

266256
class InvalidCollectionNameError extends Error {

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
"description": "MongoDB milestone snapshot database adapter for ShareDB",
55
"main": "lib/index.js",
66
"dependencies": {
7-
"mongodb": "^2.2.36 || ^3.0.0 || ^4.0.0 || ^5.0.0",
7+
"mongodb": "^3.0.0 || ^4.0.0 || ^5.0.0",
88
"sharedb": "^1.0.0 || ^2.0.0 || ^3.0.0"
99
},
1010
"devDependencies": {
1111
"chai": "^4.2.0",
1212
"coveralls": "^3.1.0",
1313
"eslint": "^7.14.0",
1414
"mocha": "^8.2.1",
15-
"mongodb2": "npm:mongodb@^2.2.36",
1615
"mongodb3": "npm:mongodb@^3.0.0",
1716
"mongodb4": "npm:mongodb@^4.0.0",
1817
"mongodb5": "npm:mongodb@^5.0.0",

test/mongo-milestone-db.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const mongodbRequire = require('../lib/mongodb');
77
const MONGO_URL = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test';
88

99
[
10-
'mongodb2',
1110
'mongodb3',
1211
'mongodb4',
1312
'mongodb5',
@@ -17,7 +16,6 @@ const MONGO_URL = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test'
1716
function create(options, callback) {
1817
if (typeof options === 'function') {
1918
callback = options;
20-
options = {};
2119
}
2220

2321
let db;
@@ -35,9 +33,7 @@ const MONGO_URL = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test'
3533
connect(MONGO_URL)
3634
.then((mongoConnection) => {
3735
mongo = mongoConnection;
38-
return MongoMilestoneDB._isLegacyMongoClient(mongo)
39-
? mongo.dropDatabase()
40-
: mongo.db().dropDatabase();
36+
return mongo.db().dropDatabase();
4137
})
4238
.then(() => {
4339
shareDbCallback(null, mongo);
@@ -65,9 +61,7 @@ const MONGO_URL = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test'
6561
create((error, createdDb, createdMongo) => {
6662
if (error) return done(error);
6763
db = createdDb;
68-
mongo = MongoMilestoneDB._isLegacyMongoClient(createdMongo)
69-
? createdMongo
70-
: createdMongo.db();
64+
mongo = createdMongo.db();
7165
done();
7266
});
7367
});
@@ -151,9 +145,7 @@ const MONGO_URL = process.env.TEST_MONGO_URL || 'mongodb://localhost:27017/test'
151145
create(options, (error, createdDb, createdMongo) => {
152146
if (error) return done(error);
153147
db = createdDb;
154-
mongo = MongoMilestoneDB._isLegacyMongoClient(createdMongo)
155-
? createdMongo
156-
: createdMongo.db();
148+
mongo = createdMongo.db();
157149
done();
158150
});
159151
});

0 commit comments

Comments
 (0)