BAE上连接rockmongo报错:connection error: [Error: failed to connect to [mongo.duapp.com:8908]]及解决
如题,各位有遇到过这种情况吗?一开始是连接正常的,connect连接后有打出日志来,但是过一会就报错了,用的是mongoose,代码如下:
var db = mongoose.createConnection(),
options = {
db: { native_parser: true },
server: { poolSize: 5 },
user: settings.user,
pass: settings.pass
};
db.open(settings.host, settings.db, settings.port, options, function() {
console.log('mongoDB connected!');
});
db.on('error', function (err) {
console.error.bind(console, 'connection error:');
//listen BAE mongodb,if except throws then close the connection
//why have to do this?Clause it'll be disconnected if it free after 30s by BAE
db.close();
});
//when close, reopen a connect
db.on('close', function() {
db.open(settings.host, settings.db, settings.port, options);
});
这样写connect相当于是你给我断了,我就把原来的close了再新开一个,现在已经解决啦,希望遇到这个问题的盆友少走弯路!参考地址