Skip to content

Commit

Permalink
Update mongo-storage.js (nightscout#6811)
Browse files Browse the repository at this point in the history
- use default time outs
- remove MongoDB_URI (including user name and password) from public error message
- fix typos

Co-authored-by: Sulka Haro <sulka@sulka.net>
  • Loading branch information
2 people authored and lpsuerj committed Apr 17, 2021
1 parent c18d6ca commit 553bb10
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/storage/mongo-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ function init(env, cb, forceNewConnection) {
}

console.log('Setting up new connection to MongoDB');
const timeout = 10 * 1000;
const options = {
connectTimeoutMS: timeout,
socketTimeoutMS: timeout,
useNewUrlParser: true,
useUnifiedTopology: true,
};
Expand All @@ -38,7 +35,7 @@ function init(env, cb, forceNewConnection) {
try {
await mongo.client.connect();

console.log('Successfully established a connected to MongoDB');
console.log('Successfully established connection to MongoDB');

const dbName = mongo.client.s.options.dbName;
mongo.db = mongo.client.db(dbName);
Expand Down Expand Up @@ -69,7 +66,7 @@ function init(env, cb, forceNewConnection) {
setTimeout(connect_with_retry, timeout, i + 1);
if (i == 1) cb(new Error('MongoDB connection failed! Double check the MONGODB_URI setting in Heroku.'), null);
} else {
cb(new Error('MONGODB_URI ' + env.storageURI + ' seems invalid: ' + err.message));
cb(new Error('MONGODB_URI seems invalid: ' + err.message));
}
}
};
Expand Down

0 comments on commit 553bb10

Please sign in to comment.