Skip to content

Commit

Permalink
Merge pull request #231 from jason-fox/feature/mongo-db
Browse files Browse the repository at this point in the history
Fix #204 - Update MongoDB to remove deprecation warnings
  • Loading branch information
fgalan authored Feb 25, 2021
2 parents 793bcc3 + 31dfddf commit 17a47ce
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/model/dbConn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/services/configurationData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down
4 changes: 2 additions & 2 deletions lib/services/protocolData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion lib/services/protocols.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
) {
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
},
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions test/mongoDBUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/unit/configuration-cache-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
2 changes: 1 addition & 1 deletion test/unit/configuration-retrieval-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 17a47ce

Please sign in to comment.