Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoose Reconnect Event is Not getting fired after some time

Mongoose 'reconnected' Event is not fired after 'close' event is getting fired after the second time. How can I increase the time to always retry?

close: Emitted after we disconnected and onClose (after this, if I start Mongo, it is not firing any event) executed on all of this connections models.

like image 740
Sireesh Vattikuti Avatar asked Sep 11 '15 06:09

Sireesh Vattikuti


1 Answers

I finally found the answer for this, We need to use the server options of mongodb-native driver options like this.

var opts = {
server: {
      auto_reconnect: true,
      reconnectInterval: 5000,
      reconnectTries: Infinity,
      socketOptions: {
        keepAlive: 1,
        connectTimeoutMS: 10000
      }
    }
}

For more options follow this document: http://mongodb.github.io/node-mongodb-native/2.0/api/Server.html

like image 177
Sireesh Vattikuti Avatar answered Oct 09 '22 19:10

Sireesh Vattikuti