From 5bdaf911ee59629d94a5b10bab3cbf3fed95f328 Mon Sep 17 00:00:00 2001 From: Jason Fox Date: Wed, 24 Feb 2021 18:07:07 +0100 Subject: [PATCH 1/2] Fix #204 - Update MongoDB to remove deprecation warnings --- lib/model/dbConn.js | 1 + lib/services/configurationData.js | 2 +- lib/services/protocolData.js | 4 ++-- lib/services/protocols.js | 2 +- package.json | 8 ++++---- test/mongoDBUtils.js | 4 ++-- test/unit/configuration-cache-test.js | 2 +- test/unit/configuration-retrieval-test.js | 2 +- 8 files changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/model/dbConn.js b/lib/model/dbConn.js index 69d9f62..fd697b4 100644 --- a/lib/model/dbConn.js +++ b/lib/model/dbConn.js @@ -108,6 +108,7 @@ function init(host, db, port, username, password, options, callback) { logger.info(context, 'Attempting to connect to MongoDB instance. Attempt %d', retries); // just to avoid warnings with recent mongoose versions options.useNewUrlParser = true; + options.useUnifiedTopology = true mongoose.set('useCreateIndex', true); /* eslint-disable-next-line no-unused-vars */ const candidateDb = mongoose.createConnection(url, options, function(error, result) { diff --git a/lib/services/configurationData.js b/lib/services/configurationData.js index af54036..6847963 100644 --- a/lib/services/configurationData.js +++ b/lib/services/configurationData.js @@ -79,7 +79,7 @@ function createGetWithFields(fields) { query.skip(parseInt(offset, 10)); } - async.series([query.exec.bind(query), Configuration.model.count.bind(Configuration.model, queryObj)], function ( + async.series([query.exec.bind(query), Configuration.model.countDocuments.bind(Configuration.model, queryObj)], function ( error, results ) { diff --git a/lib/services/protocolData.js b/lib/services/protocolData.js index 213ca7a..877b8d3 100644 --- a/lib/services/protocolData.js +++ b/lib/services/protocolData.js @@ -54,7 +54,7 @@ function processConfiguration(protocol, description, iotagent, resource, configu } function cleanConfigurations(protocol, iotagent, resource, callback) { - Configuration.model.remove( + Configuration.model.deleteOne( { protocol, iotagent, @@ -162,7 +162,7 @@ function removeProtocol(id, callback) { logger.debug(context, 'Removing protocol with id [%s]', id); /* eslint-disable-next-line no-unused-vars */ - Protocol.model.remove(condition, function(error, results) { + Protocol.model.deleteOne(condition, function(error, results) { if (error) { logger.debug(context, 'Internal MongoDB Error getting device: %s', error); diff --git a/lib/services/protocols.js b/lib/services/protocols.js index 7f7bde8..94ba930 100644 --- a/lib/services/protocols.js +++ b/lib/services/protocols.js @@ -46,7 +46,7 @@ function readProtocolList(req, res, next) { query.skip(parseInt(req.query.offset, 10)); } - async.series([query.exec.bind(query), Protocol.model.count.bind(Protocol.model, condition)], function( + async.series([query.exec.bind(query), Protocol.model.countDocuments.bind(Protocol.model, condition)], function( error, results ) { diff --git a/package.json b/package.json index 1b82586..16871b7 100644 --- a/package.json +++ b/package.json @@ -19,10 +19,10 @@ "node": ">=12" }, "scripts": { - "clean": "rm -rf package-lock.json && rm -rf node_modules && rm -rf coverage", + "clean": "rm -rf package-lock.json && rm -rf node_modules && rm -rf coverage && rm -rf .nyc_output", "healthcheck": "node ./bin/healthcheck", "lint": "eslint lib/ bin/iota-manager test/ --cache --fix", - "test": "nyc --reporter=text mocha --recursive 'test/**/*.js' --reporter spec --timeout 3000 --ui bdd --exit", + "test": "nyc --reporter=text mocha --recursive 'test/**/*.js' --reporter spec --timeout 3000 --ui bdd --exit --color true", "test:coverage": "nyc --reporter=lcov mocha -- --recursive 'test/**/*.js' --reporter spec --exit", "test:watch": "npm run test -- -w ./lib", "watch": "watch 'npm test && npm run lint' ./lib ./test" @@ -34,7 +34,7 @@ "logops": "2.1.0", "underscore": "~1.7.0", "revalidator": "~0.3.1", - "mongoose": "5.7.7", + "mongoose": "5.11.18", "async": "2.6.2", "iotagent-node-lib": "git://github.com/telefonicaid/iotagent-node-lib.git#master" }, @@ -45,7 +45,7 @@ "husky": "~4.2.5", "lint-staged": "~10.2.11", "mocha": "8.0.1", - "mongodb": "3.5.9", + "mongodb": "3.6.4", "nock": "13.0.3", "nyc": "~15.1.0", "prettier": "~2.0.5", diff --git a/test/mongoDBUtils.js b/test/mongoDBUtils.js index ea6cb64..9f6d33d 100644 --- a/test/mongoDBUtils.js +++ b/test/mongoDBUtils.js @@ -31,7 +31,7 @@ function cleanDb(host, name, callback) { MongoClient.connect( url, - { useNewUrlParser: true }, + { useNewUrlParser: true, useUnifiedTopology: true }, function(err, db) { if (db && db.db()) { db.db().dropDatabase(function(err, result) { @@ -52,7 +52,7 @@ function populate(host, dbName, entityList, collectionName, callback) { MongoClient.connect( url, - { useNewUrlParser: true }, + { useNewUrlParser: true, useUnifiedTopology: true }, function(err, db) { if (db) { db.db() diff --git a/test/unit/configuration-cache-test.js b/test/unit/configuration-cache-test.js index f69183c..fbe1493 100644 --- a/test/unit/configuration-cache-test.js +++ b/test/unit/configuration-cache-test.js @@ -45,7 +45,7 @@ describe('Configuration cache', function () { }; beforeEach(function (done) { async.series([mongoDBUtils.cleanDbs, async.apply(iotManager.start, iotConfig)], function () { - mongo.connect('mongodb://localhost:27017/iotagent-manager', { useNewUrlParser: true }, function (err, db) { + mongo.connect('mongodb://localhost:27017/iotagent-manager', { useNewUrlParser: true, useUnifiedTopology: true }, function (err, db) { iotmDb = db; done(); }); diff --git a/test/unit/configuration-retrieval-test.js b/test/unit/configuration-retrieval-test.js index 717734f..5a42851 100644 --- a/test/unit/configuration-retrieval-test.js +++ b/test/unit/configuration-retrieval-test.js @@ -86,7 +86,7 @@ describe('Configuration list', function() { async.series([mongoDBUtils.cleanDbs, async.apply(iotManager.start, iotConfig)], function() { mongo.connect( 'mongodb://localhost:27017/iotagent-manager', - { useNewUrlParser: true }, + { useNewUrlParser: true, useUnifiedTopology: true }, function(err, db) { iotmDb = db; From 31dfddfd900acb635e8847add349a9ae0a6293a6 Mon Sep 17 00:00:00 2001 From: Jason Fox Date: Thu, 25 Feb 2021 11:45:39 +0100 Subject: [PATCH 2/2] Update CHANGES_NEXT_RELEASE --- CHANGES_NEXT_RELEASE | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 456fb0d..bae453f 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,2 +1,4 @@ - Upgrade NodeJS version from 10 to 12 in Dockerfile due to Node 10 End-of-Life - Set Nodejs 12 as minimum version in packages.json (effectively removing Nodev10 from supported versions) +- Upgrade mongodb dev dependency from 3.5.9 to 3.6.4 +- Upgrade mongoose dependency from 5.7.7 to 5.11.18