我想增加mongoose的连接超时,因为我的MongoDB需要一些时间来启动。
// I have also tried
// var mongooseOptions = { replset: { socketOptions: { connectTimeoutMS : config.mongodb.dbTimeout }}};
var mongooseOptions = { server: { socketOptions: { connectTimeoutMS: config.mongodb.dbTimeout }}};
logger.info('Establishing connection to MongoDB... (Timeout is ' + config.mongodb.dbTimeout + ')');
mongoose.connect(config.mongodb.uri, mongooseOptions, function (error) {
if (error) {
logger.error('Connection to MongoDB failed: ' + error);
return;
}
...
但是没有应用超时,它立即失败:
2015-04-24T10:43:10.156Z - info: Establishing connection to MongoDB... (Timeout is 300000)
2015-04-24T10:43:10.275Z - error: Connection to MongoDB failed: MongoError: connect ECONNREFUSED
编辑:我正在使用Mongoose 4.0.1