Skip to content

Commit

Permalink
Merge pull request #277 from telefonicaid/hardening/upgrade-mongodb-t…
Browse files Browse the repository at this point in the history
…o-4.x

FIX upgrade mongodb to 4.x
  • Loading branch information
AlvaroVega authored Jun 23, 2022
2 parents 80ff665 + ff17dd1 commit 5ba33d1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 29 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Fix: replace git:// to https:// url for npm dependences
- Fix: Dockerfile to include initial packages upgrade
- Upgrade mongodb dev dep from 3.5.9 to 4.7.0
- Upgrade NodeJS version from 14-slim to 16-slim in Dockerfile
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"husky": "~4.2.5",
"lint-staged": "~10.2.11",
"mocha": "8.0.1",
"mongodb": "3.5.9",
"mongodb": "4.7.0",
"nock": "13.0.3",
"nyc": "~15.1.0",
"prettier": "~2.0.5",
Expand Down
51 changes: 23 additions & 28 deletions test/unit/mongoDBUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,34 @@ function cleanDb(host, name, callback) {
// FIXME: this code doesn't work with MongoDB replica set, we are assuming that an
// standalone MongoDB instance is used to run unit test.To use a replica set this
// needs to be adapted
// FIXME: not sure if the statement above is still valid after moving to mongodb 4.x.
// Maybe the limitation has been overpassed
const url = 'mongodb://' + host + ':27017/' + name;
MongoClient.connect(
url,
{
useNewUrlParser: true,
connectTimeoutMS: 500
},
function(err, db) {
if (db) {
const collections = ['devices', 'groups', 'entities', 'registrations'];
MongoClient.connect(url, function (err, db) {
if (db) {
const collections = ['devices', 'groups', 'entities', 'registrations'];

async.eachSeries(
collections,
function(collection, innerCb) {
const collectionDB = db.db(name).collection(collection);
if (collectionDB) {
collectionDB.drop(function(err, delOK) {
innerCb();
});
} else {
async.eachSeries(
collections,
function (collection, innerCb) {
const collectionDB = db.db(name).collection(collection);
if (collectionDB) {
collectionDB.drop(function (err, delOK) {
innerCb();
}
},
function(err) {
db.close();
callback();
});
} else {
innerCb();
}
);
} else {
callback();
}
},
function (err) {
db.close();
callback();
}
);
} else {
callback();
}
);
});
}

function cleanDbs(host, callback) {
Expand Down

0 comments on commit 5ba33d1

Please sign in to comment.