mongodb 链接数的问题
发布于 11 年前 作者 xianggp 7994 次浏览 最后一次编辑是 8 年前

使用 session-mongodb 存储session 时,默认会产生5条数据库链接

Mon Jul 01 15:43:50.377 [initandlisten] connection accepted from 127.0.0.1:37821
 #1 (1 connection now open)
Mon Jul 01 15:43:50.385 [initandlisten] connection accepted from 127.0.0.1:37822
 #2 (2 connections now open)
Mon Jul 01 15:43:50.385 [initandlisten] connection accepted from 127.0.0.1:37823
 #3 (3 connections now open)
Mon Jul 01 15:43:50.385 [initandlisten] connection accepted from 127.0.0.1:37824
 #4 (4 connections now open)
Mon Jul 01 15:43:50.393 [initandlisten] connection accepted from 127.0.0.1:37825
 #5 (5 connections now open)
Mon Jul 01 15:44:05.612 [initandlisten] connection accepted from 127.0.0.1:37828
 #6 (6 connections now open)
Mon Jul 01 15:44:05.627 [conn6] end connection 127.0.0.1:37828 (5 connections no
w open)

其实应该是一条链接的,应该怎么做啊 app.js配置

var MongoStore = require('session-mongoose')(express);
var settings = require('./Settings');
var sessionStore = new MongoStore({
  db:settings.db
},function(){
  console.log('connect mongodb success...');
});
app.use(express.session({
    secret:settings.db,
    store:sessionStore,
    cookie:{
      maxAge:new Date(Date.now()+1000*60*60)
    }
}));
3 回复

看文档,创建MongoStore是有参数的,搞不清楚你要设成1干什么?这里5个连接还是小了点

1、那按照您的意思,五个链接应该属正常的了? 2、你所说的参数是指这个吗?

var sessionStore = new MongoStore({
    url: "mongodb://localhost/session",
    interval: 120000 // expiration check worker run interval in millisec (default: 60000)
});

3、你说的我设成1 是指哪里?没搞明白。 4、谢谢你的指导。

mongodb://localhost/session?poolSize=5,如果不指定默认是5,可以设大一点

回到顶部