Error setting TTL index on collection :sessions
发布于 9 年前 作者 aeolusheath 5092 次浏览 最后一次编辑是 8 年前 来自 问答

好蛋疼啊 我在公司不会报错··自己在家做会报这个错误····· 卡住了 网上找了··没有明确的答复啊·· 求帮助 app.use(session({ saveUninitialized: true, resave: false, secret: settings.cookieSecret, key: settings.db,//cookie name cookie: {maxAge: 1000 * 60 * 60 * 24 * 30},//30 days store: new MongoStore({ db: settings.db, host: settings.host, port: settings.port }) }));

3 回复
		 node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/base.js:242
  		  throw message;      
           ^
		 Error: Error setting TTL index on collection : sessions
	    我也是同样的报错,不能设置这个索引.
	    然后我直接注释了那段代码,
        然而并没有什么影响.
         self.collection = collection;
        // Make sure we have a TTL index on "expires", so mongod will automatically
        // remove expired sessions. expireAfterSeconds is set to 0 because we want 
        // mongo to remove anything expired without any additional delay.
        self.collection.ensureIndex({expires: 1}, {expireAfterSeconds: 0}, function(err, result) {
          //  nothing
          //  none of my bussines?
		  // 只是为了自动清楚过期会话嘛,mongodb版本更新后不一样了?
		  //  https://github.com/nswbmw
          /* if (err) {
               throw new Error('Error setting TTL index on collection : ' + self.db_collection_name);
         } */ 
          
          callback && callback(self.collection);
        });
	db.sessions.ensureIndex({expires: 1}, {expireAfterSeconds: 0});
  1. 在shell中自行建立索引是可行的.
	self.collection = collection;
  1. 是不是这个collection的指向不是sessions?
	mongdb 2.6X

3.宿主机3.0和mongolab 2.6版本都会报这个错误. 4.按照(3)创建的索引起不到自动清除session的作用,session一直在增加.

看来还不懂mongodb,尚未推出Node正式版之前,先观望着吧。

回到顶部