Skip to content

Commit

Permalink
💥 BREAKING: drop mongodb@2 support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
alecgibson committed Feb 28, 2023
1 parent a49c324 commit 023f2b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
21 changes: 3 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,6 @@ ShareDbMongo.prototype.getDbs = function(callback) {
}, callback);
};

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

ShareDbMongo.prototype._connect = function(mongo, options) {
// Create the mongo connection client connections if needed
//
Expand All @@ -148,17 +138,12 @@ ShareDbMongo.prototype._connect = function(mongo, options) {
return Promise.all(connections).then(function(clients) {
var mongoClient = clients[0];
var mongoPollClient = clients[1];
var result = {
mongo: mongoClient,
return {
mongo: mongoClient.db(),
mongoClient: mongoClient,
mongoPoll: mongoPollClient,
mongoPoll: mongoPollClient && mongoPollClient.db(),
mongoPollClient: mongoPollClient
};
if (!isLegacyMongoClient(mongoClient)) {
result.mongo = mongoClient.db();
if (mongoPollClient) result.mongoPoll = mongoPollClient.db();
}
return result;
});
};

Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "MongoDB database adapter for ShareDB",
"main": "index.js",
"dependencies": {
"mongodb": "^2.1.2 || ^3.1.13 || ^4.0.0 || ^5.0.0",
"mongodb": "^3.1.13 || ^4.0.0 || ^5.0.0",
"sharedb": "^1.9.1 || ^2.0.0 || ^3.0.0"
},
"devDependencies": {
Expand All @@ -13,7 +13,6 @@
"eslint": "^5.16.0",
"eslint-config-google": "^0.13.0",
"mocha": "^6.2.2",
"mongodb2": "npm:mongodb@^2.1.2",
"mongodb3": "npm:mongodb@^3.0.0",
"mongodb4": "npm:mongodb@^4.0.0",
"mongodb5": "npm:mongodb@^5.0.0",
Expand All @@ -27,11 +26,10 @@
"lint": "./node_modules/.bin/eslint --ignore-path .gitignore '**/*.js'",
"lint:fix": "npm run lint -- --fix",
"test": "mocha",
"test:mongodb2": "_SHAREDB_MONGODB_DRIVER=mongodb2 npm test",
"test:mongodb3": "_SHAREDB_MONGODB_DRIVER=mongodb3 npm test",
"test:mongodb4": "_SHAREDB_MONGODB_DRIVER=mongodb4 npm test",
"test:mongodb5": "_SHAREDB_MONGODB_DRIVER=mongodb5 npm test",
"test:all": "npm run test:mongodb2 && npm run test:mongodb3 && npm run test:mongodb4 && npm run test:mongodb5",
"test:all": "npm run test:mongodb3 && npm run test:mongodb4 && npm run test:mongodb5",
"test-cover": "nyc --temp-dir=coverage -r text -r lcov npm run test:all"
},
"repository": "git://github.com/share/sharedb-mongo.git",
Expand Down

0 comments on commit 023f2b2

Please sign in to comment.