MongoDB"错误设置集合上的TTL索引:会话"

时间:2015-07-19 12:13:27

标签: node.js mongodb

我在服务器中构建了一个博客系统。使用Express.js和Mongodb。 它工作很长时间,直到今天我在MongoDB中添加了身份验证功能。我不能打开我的博客,错误打印在nodejs shell下面:

D:\blog\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\connection\base.js:242
    throw message;
          ^
Error: Error setting TTL index on collection : sessions
at D:\blog\node_modules\connect-mongo\lib\connect-mongo.js:161:23
at D:\blog\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\db.js:1404:28
at D:\blog\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\db.js:1542:30
at D:\blog\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\cursor.js:159:22
at D:\blog\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\cursor.js:685:39
at Cursor.close (D:\blog\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\cursor.js:959:5)
at commandHandler (D:\blog\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\cursor.js:685:21)
at D:\blog\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\db.js:1806:9
at Server.Base._callHandler (D:\blog\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\connection\base.js:442:41)
at D:\blog\node_modules\connect-mongo\node_modules\mongodb\lib\mongodb\connection\server.js:485:18

附上我的app.js:

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var settings = require('./settings');
var flash = require('connect-flash');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);

var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(flash());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use(session({
  secret: settings.cookieSecret,
  key: settings.db,//cookie name
  cookie: {maxAge: 1000 * 60 * 60 * 24 * 30},//30 days
  resave: false,
  saveUninitialized: false,
  store: new MongoStore({
    db: settings.db,
    host: settings.host,
    port: settings.port,
    auto_reconnect: true
  })
}));

routes(app);
module.exports = app;

你们知道发生了什么吗?它是由系统试图在授权之前将会话插入集合引起的吗?因为我在MongoDB中添加了身份验证后发生了。

=======================

现在我已经更新了我的模块&connect; mongo'版本从0.4到0.8.0

然后我启动nodejs,它崩溃,出现以下错误:

D:\blog\node_modules\mongodb\lib\mongodb\connection\base.js:246
        throw message;
              ^
MongoError: not authorized for query on blog.system.indexes
    at Object.toError (D:\blog\node_modules\mongodb\lib\mongodb\utils.js:114:11)

    at D:\blog\node_modules\mongodb\lib\mongodb\cursor.js:700:54
    at Cursor.close (D:\blog\node_modules\mongodb\lib\mongodb\cursor.js:989:5)
    at commandHandler (D:\blog\node_modules\mongodb\lib\mongodb\cursor.js:700:21
)
    at D:\blog\node_modules\mongodb\lib\mongodb\db.js:1912:9
    at Server.Base._callHandler (D:\blog\node_modules\mongodb\lib\mongodb\connec
tion\base.js:448:41)
    at D:\blog\node_modules\mongodb\lib\mongodb\connection\server.js:481:18
    at MongoReply.parseBody (D:\blog\node_modules\mongodb\lib\mongodb\responses\
mongo_reply.js:68:5)
    at null.<anonymous> (D:\blog\node_modules\mongodb\lib\mongodb\connection\ser
ver.js:439:20)
    at emit (events.js:107:17)

0 个答案:

没有答案