express 搭建博客时connect-mongo出错
发布于 9 年前 作者 liushaobo05 3685 次浏览 最后一次编辑是 8 年前 来自 问答

/home/node/program/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 /home/node/program/blog/node_modules/connect-mongo/lib/connect-mongo.js:161:23 at /home/node/program/blog/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1404:28 at /home/node/program/blog/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1542:30 at /home/node/program/blog/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:159:22 at /home/node/program/blog/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:685:39 at Cursor.close (/home/node/program/blog/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:959:5) at commandHandler (/home/node/program/blog/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/cursor.js:685:21) at /home/node/program/blog/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/db.js:1806:9 at Server.Base._callHandler (/home/node/program/blog/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/base.js:442:41) at /home/node/program/blog/node_modules/connect-mongo/node_modules/mongodb/lib/mongodb/connection/server.js:485:18 Program node app exited with code 1

Starting child process with 'node app’ Failed to load c++ bson extension, using pure JS version [Error: Module did not self-register.] js-bson: Failed to load c++ bson extension, using pure JS version 查看了几个相关连接,未能解决,求大神指教 http://cnodejs.org/topic/55a7c0744ff0b93433c2fd77 http://stackoverflow.com/questions/22698661/mongodb-error-setting-ttl-index-on-collection-sessions http://stackoverflow.com/questions/23390768/error-setting-ttl-index-on-collection-sessions-mongodb-mongohq

3 回复

把"mongodb" 和 "connect-mongo"版本号更到最新

在你的app.js里添加 var session = require(‘express-session’); var MongoStore = require(‘connect-mongo’)(session);

app.use(session({ 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 }) }));

用的是最新版的话 改成这个 store: new MongoStore({ url: ‘mongodb://localhost/blog’ })

回到顶部