请教:为什么我在用mongodb时,在 db.open() 这个时候,有时候会报错:connection closed
代码如下:
var poolModule = require(‘generic-pool’);
exports.dbpool = pool = poolModule.Pool({
name : 'mongo’,
create : function(callback) {
var server_options = {
auto_reconnect: true
},
db_options = {
native_parser: true,
strict: false,
safe: false
};
var mongo = require(“mongodb”);
var mongoServer = new mongo.Server('10.0.0.125’, 27017, server_options);
dbName = 'test’;
db = new mongo.Db(dbName, mongoServer, db_options);
db.open(function(err, client){
if(err){
console.log('Error open db: '+err);
return false;
}
if(callback) callback(err, client);
});
},
destroy : function(client) {
client.close();
},
max : 50,
idleTimeoutMillis :30000,
log : false
});