blu
blu

Reputation: 13175

mongoose connection connectTimeoutMS

I can't seem to get my mongo connection to timeout faster than the default.

var databaseUrl = 'mongodb://localhost/doesnotexist';
var options = { server: { connectTimeoutMS: 10000 } };

var db = mongoose.connect(databaseUrl, options, function (err) {
    ...
}

I am trying to simulate the DB going offline to test the failover to message queues, but can't seem to get this to work.

Any help with this would be great, thanks.

Upvotes: 2

Views: 5151

Answers (1)

aaronheckmann
aaronheckmann

Reputation: 10780

connectTimeoutMS is a socket option which is specified like so:

var databaseUrl = 'mongodb://localhost/doesnotexist';
var options = { server: { socketOptions: { connectTimeoutMS: 10000 }}};

var db = mongoose.connect(databaseUrl, options, function (err) {

})

Upvotes: 3

Related Questions