mongoose的问题,每次增删改查都要打开关闭时吗
答案:2 悬赏:60 手机版
解决时间 2021-04-07 21:27
- 提问者网友:饥饿走向夜
- 2021-04-07 01:52
mongoose的问题,每次增删改查都要打开关闭时吗
最佳答案
- 五星知识达人网友:想偏头吻你
- 2021-04-07 02:26
使用mongoose内置的连接池,配置如下
options = {
server: {
auto_reconnect: true,
poolSize: 10
}
};
说明:
poolSize是连接池大小
auto_reconnect是否自动重连接
代码
// mongoose config
var mongoose = require('mongoose')
, connectionString = 'mongodb://localhost:27017/exam_weixin'
, options = {};
options = {
server: {
auto_reconnect: true,
poolSize: 10
}
};
mongoose.connect(connectionString, options, function(err, res) {
if(err) {
console.log('[mongoose log] Error connecting to: ' + connectionString + '. ' + err);
} else {
console.log('[mongoose log] Successfully connected to: ' + connectionString);
}
});
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'mongoose connection error:'));
db.once('open', function callback () {
// yay!
console.log('mongoose open success');
});
options = {
server: {
auto_reconnect: true,
poolSize: 10
}
};
说明:
poolSize是连接池大小
auto_reconnect是否自动重连接
代码
// mongoose config
var mongoose = require('mongoose')
, connectionString = 'mongodb://localhost:27017/exam_weixin'
, options = {};
options = {
server: {
auto_reconnect: true,
poolSize: 10
}
};
mongoose.connect(connectionString, options, function(err, res) {
if(err) {
console.log('[mongoose log] Error connecting to: ' + connectionString + '. ' + err);
} else {
console.log('[mongoose log] Successfully connected to: ' + connectionString);
}
});
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'mongoose connection error:'));
db.once('open', function callback () {
// yay!
console.log('mongoose open success');
});
全部回答
- 1楼网友:天凉才是好个秋
- 2021-04-07 02:51
我也不确定,还是看看专业人士怎么说。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯