diff --git a/index.js b/index.js index 8ad2bdc..3d9888d 100644 --- a/index.js +++ b/index.js @@ -1504,6 +1504,11 @@ var collectionOperationsMap = { var err = ShareDbMongo.malformedQueryOperatorError('$mapReduce'); return cb(err); } + // This function was removed in mongodb5: + // https://github.com/mongodb/node-mongodb-native/pull/3511 + if (typeof collection.mapReduce !== 'function') { + var err = ShareDbMongo.$mapReduceDisabledError(); + } var mapReduceOptions = { query: query, out: {inline: 1}, diff --git a/package.json b/package.json index 03f9ad3..3183708 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "MongoDB database adapter for ShareDB", "main": "index.js", "dependencies": { - "mongodb": "^2.1.2 || ^3.1.13 || ^4.0.0", + "mongodb": "^2.1.2 || ^3.1.13 || ^4.0.0 || ^5.0.0", "sharedb": "^1.9.1 || ^2.0.0 || ^3.0.0" }, "devDependencies": { @@ -16,6 +16,7 @@ "mongodb2": "npm:mongodb@^2.1.2", "mongodb3": "npm:mongodb@^3.0.0", "mongodb4": "npm:mongodb@^4.0.0", + "mongodb5": "npm:mongodb@^5.0.0", "nyc": "^14.1.1", "ot-json1": "^1.0.1", "sharedb-mingo-memory": "^1.1.1", @@ -29,7 +30,8 @@ "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:all": "npm run test:mongodb2 && npm run test:mongodb3 && npm run test:mongodb4", + "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-cover": "nyc --temp-dir=coverage -r text -r lcov npm run test:all" }, "repository": "git://github.com/share/sharedb-mongo.git", diff --git a/test/test_mongo.js b/test/test_mongo.js index c288633..40d0e4a 100644 --- a/test/test_mongo.js +++ b/test/test_mongo.js @@ -334,6 +334,11 @@ describe('mongo db', function() { }); it('$mapReduce queries should work when allowJavaScriptQuery == true', function(done) { + if (process.env._SHAREDB_MONGODB_DRIVER === 'mongodb5') { + // This function was removed in mongodb5: + // https://github.com/mongodb/node-mongodb-native/pull/3511 + return done(); + } var snapshots = [ {type: 'json0', v: 1, data: {player: 'a', round: 1, score: 5}}, {type: 'json0', v: 1, data: {player: 'a', round: 2, score: 7}},