Skip to content

Commit

Permalink
Merge pull request #5 from nightscout/dev
Browse files Browse the repository at this point in the history
npm update / mongo fix / small fixes (nightscout#3413)
  • Loading branch information
UphwbKpqSm47z3qewH9x authored Apr 3, 2018
2 parents bd0bfac + bfce345 commit 91bf226
Show file tree
Hide file tree
Showing 6 changed files with 10,318 additions and 5,396 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ language: node_js
sudo: required
dist: trusty
node_js:
- "8.9.3"
before_install: if [[ `npm --version` != "5.6" ]]; then npm install -g npm@latest; npm --version; fi
- "8"
- "9"
before_install: if [[ `npm --version` != "5.8.0" ]]; then npm install -g npm@latest; npm --version; fi
matrix:
fast_finish: true
services:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ Community maintained fork of the

Requirements:

- [Node.js](http://nodejs.org/) 8.9.0 LTS (use [Install instructions for Node](https://nodejs.org/en/download/package-manager/) or `setup.sh`)
- [Node.js](http://nodejs.org/) 8.11.0 LTS or later or [Node.js](http://nodejs.org/) 9.10.0 or later. Use [Install instructions for Node](https://nodejs.org/en/download/package-manager/) or `setup.sh`)
- [MongoDB](https://www.mongodb.com/download-center?jmp=nav#community) 3.x. MongoDB 2.4 is only supported for Raspberry Pi.

Clone this repo then install dependencies into the root of the project:

Expand Down
20 changes: 12 additions & 8 deletions lib/storage/mongo-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,22 @@ function init (env, cb, forceNewConnection) {
var connect_with_retry = function(i) {
return MongoClient.connect(env.storageURI, options, function connected(err, client) {
if (err) {
if (err.includes('Invalid schema')) { throw new Error('MongoDB connection string seems invalid'); }
if (i>20) {
// Abort after retrying for more than 10 minutes
throw 'Error connecting to MongoDB, stopping the retry loop and aborting...';
//console.log('err=', err)
if (err.name && err.name === "MongoNetworkError") {
if (i>20) {
// Abort after retrying for more than 10 minutes
throw 'Error connecting to MongoDB, stopping the retry loop and aborting...';
}
console.log('Error connecting to MongoDB: %j - retrying in ' + i*3 + ' sec', err);
setTimeout(connect_with_retry, i*3000, i+1);
} else if (err.message) {
throw new Error('MongoDB connection string '+env.storageURI+' seems invalid: '+err.message) ;
}
console.log('Error connecting to MongoDB: %j - retrying in ' + i*3 + ' sec', err);
setTimeout(connect_with_retry, i*3000, i+1);
} else {
console.log('Successfully established a connected to MongoDB');

var dbName = env.storageURI.split('?').pop().split('/');
dbName = dbName[dbName.length -1];
var dbName = env.storageURI.split('/').pop().split('?');
dbName=dbName[0]; // drop Connection Options
mongo.db = client.db(dbName);
connection = mongo.db;
mongo.client = client;
Expand Down
Loading

0 comments on commit 91bf226

Please sign in to comment.