FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 3488 Ask New Question


I know my network is little unstable, but i want to make my mongo driver retry forever how can i make that change?
Currently i am getting following exception and even my network is back mongo driver is not establishing the connection.

Error: read ECONNRESET
    at exports._errnoException (util.js:1024:11)
    at TCP.onread (net.js:610:25)
(node:90835) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: res.Stats is not a function
(node:90835) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
On By


1 Answer


You can use 'reconnectTries' & 'autoReconnect' parameters to make your connection retry forever.
Update your mongo connection code to the following

var db = {};
var mongoDbUri = "mongodb://db_user:[email protected]:27017/db_name";
var settings = {
      reconnectTries : Number.MAX_VALUE,
      autoReconnect : true
};
MongoClient.connect(mongoDbUri, settings, function(err, dbref) {
  if (!err) {
    console.log("Mongodb connected");
    db = dbref;
  }else{
    console.log("Error while connecting to mongoDB" + err);
  }
});
On By


Answer This Question


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News