Skip to content

Commit 91912ca

Browse files
committed
⬆️ Add mongodb@5 driver support
This is a non-breaking change that adds support for the new [`mongodb@5`][1] driver. Note that any consumers who use the new driver will lose access to `$mapReduce`, since this was [removed upstream][2]. We keep this functionality for the older drivers. [1]: https://github.com/mongodb/node-mongodb-native/releases/tag/v5.0.0 [2]: mongodb/node-mongodb-native#3511
1 parent aa03087 commit 91912ca

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

index.js

+5
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,11 @@ var collectionOperationsMap = {
15211521
var err = ShareDbMongo.malformedQueryOperatorError('$mapReduce');
15221522
return cb(err);
15231523
}
1524+
// This function was removed in mongodb5:
1525+
// https://github.com/mongodb/node-mongodb-native/pull/3511
1526+
if (typeof collection.mapReduce !== 'function') {
1527+
var err = ShareDbMongo.$mapReduceDisabledError();
1528+
}
15241529
var mapReduceOptions = {
15251530
query: query,
15261531
out: {inline: 1},

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "MongoDB database adapter for ShareDB",
55
"main": "index.js",
66
"dependencies": {
7-
"mongodb": "^2.1.2 || ^3.1.13 || ^4.0.0",
7+
"mongodb": "^2.1.2 || ^3.1.13 || ^4.0.0 || ^5.0.0",
88
"sharedb": "^1.9.1 || ^2.0.0 || ^3.0.0"
99
},
1010
"devDependencies": {
@@ -16,6 +16,7 @@
1616
"mongodb2": "npm:mongodb@^2.1.2",
1717
"mongodb3": "npm:mongodb@^3.0.0",
1818
"mongodb4": "npm:mongodb@^4.0.0",
19+
"mongodb5": "npm:mongodb@^5.0.0",
1920
"nyc": "^14.1.1",
2021
"ot-json1": "^1.0.1",
2122
"sharedb-mingo-memory": "^1.1.1",
@@ -29,7 +30,8 @@
2930
"test:mongodb2": "_SHAREDB_MONGODB_DRIVER=mongodb2 npm test",
3031
"test:mongodb3": "_SHAREDB_MONGODB_DRIVER=mongodb3 npm test",
3132
"test:mongodb4": "_SHAREDB_MONGODB_DRIVER=mongodb4 npm test",
32-
"test:all": "npm run test:mongodb2 && npm run test:mongodb3 && npm run test:mongodb4",
33+
"test:mongodb5": "_SHAREDB_MONGODB_DRIVER=mongodb5 npm test",
34+
"test:all": "npm run test:mongodb2 && npm run test:mongodb3 && npm run test:mongodb4 && npm run test:mongodb5",
3335
"test-cover": "nyc --temp-dir=coverage -r text -r lcov npm run test:all"
3436
},
3537
"repository": "git://github.com/share/sharedb-mongo.git",

test/test_mongo.js

+5
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ describe('mongo db', function() {
334334
});
335335

336336
it('$mapReduce queries should work when allowJavaScriptQuery == true', function(done) {
337+
if (process.env._SHAREDB_MONGODB_DRIVER === 'mongodb5') {
338+
// This function was removed in mongodb5:
339+
// https://github.com/mongodb/node-mongodb-native/pull/3511
340+
return done();
341+
}
337342
var snapshots = [
338343
{type: 'json0', v: 1, data: {player: 'a', round: 1, score: 5}},
339344
{type: 'json0', v: 1, data: {player: 'a', round: 2, score: 7}},

0 commit comments

Comments
 (0)