From 7a39c6f70be58ae03c44cd4b4c25f04dff3e6f86 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Wed, 16 Nov 2016 22:48:41 +0000 Subject: [PATCH] reduce Mongo db connection retry warnings only report on first attempt to close issue 1052 on main project --- storage/mongodb/66-mongodb.js | 11 ++++++++--- storage/mongodb/package.json | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/storage/mongodb/66-mongodb.js b/storage/mongodb/66-mongodb.js index 447ae2db..3b43436e 100644 --- a/storage/mongodb/66-mongodb.js +++ b/storage/mongodb/66-mongodb.js @@ -35,7 +35,6 @@ module.exports = function(RED) { return selector; } - function MongoOutNode(n) { RED.nodes.createNode(this,n); this.collection = n.collection; @@ -47,16 +46,19 @@ module.exports = function(RED) { this.mongoConfig = RED.nodes.getNode(this.mongodb); this.status({fill:"grey",shape:"ring",text:RED._("mongodbstatus.connecting")}); var node = this; + var noerror = true; var connectToDB = function() { MongoClient.connect(node.mongoConfig.url, function(err, db) { if (err) { node.status({fill:"red",shape:"ring",text:RED._("mongodb.status.error")}); - node.error(err); + if (noerror) { node.error(err); } + noerror = false; node.tout = setTimeout(connectToDB, 10000); } else { node.status({fill:"green",shape:"dot",text:RED._("mongodb.status.connected")}); node.clientDb = db; + noerror = true; var coll; if (node.collection) { coll = db.collection(node.collection); @@ -162,16 +164,19 @@ module.exports = function(RED) { this.mongoConfig = RED.nodes.getNode(this.mongodb); this.status({fill:"grey",shape:"ring",text:RED._("mongodb.status.connecting")}); var node = this; + var noerror = true; var connectToDB = function() { MongoClient.connect(node.mongoConfig.url, function(err,db) { if (err) { node.status({fill:"red",shape:"ring",text:RED._("mongodb.status.error")}); - node.error(err); + if (noerror) { node.error(err); } + noerror = false; node.tout = setTimeout(connectToDB, 10000); } else { node.status({fill:"green",shape:"dot",text:RED._("mongodb.status.connected")}); node.clientDb = db; + noerror = true; var coll; if (node.collection) { coll = db.collection(node.collection); diff --git a/storage/mongodb/package.json b/storage/mongodb/package.json index ae04681e..5cc424cb 100644 --- a/storage/mongodb/package.json +++ b/storage/mongodb/package.json @@ -1,6 +1,6 @@ { "name" : "node-red-node-mongodb", - "version" : "0.0.10", + "version" : "0.0.11", "description" : "Node-RED nodes to talk to an Mongo database", "dependencies" : { "mongodb" : "^2.2.11"