Damian
Damian

Reputation: 974

mongoose dropped connection after some inactivity and node js app crashes

enter image description here

basically I see this when I wake up and see my monitor..

so I am pretty certain this happens after some time of inactivity..

I am using mlab as my DaaS.

var connection = mongoose.connect(mongoURL, (error, database) => {
if (error) return console.log(error);
console.log('[Success: connected to mlab database]');
});

this is my connection code..

Upvotes: 1

Views: 447

Answers (2)

Mohit Rathi
Mohit Rathi

Reputation: 50

I also faced similar issue with mlab. Try this:

mongoose.Promise = global.Promise;
var mongoConnectOpts = { 
    poolSize: 50,
    reconnectTries: 10,
    reconnectInterval: 500, 
    socketOptions: {
       keepAlive: 300000, connectTimeoutMS: 30000
    }
}
mongoose.connect(config.connectionString, { server: mongoConnectOpts, replset: mongoConnectOpts });

Upvotes: 1

pneumee
pneumee

Reputation: 494

Looks like setting a keepAlive might help. mLab's recommended connection settings for mongoose:

https://gist.github.com/mongolab-org/9959376

Upvotes: 0

Related Questions