Passport.js和MongoStore错误"在MongoStore上找不到连接策略"

时间:2015-12-21 20:55:01

标签: javascript node.js mongodb mongoose passport.js

我在Node.js服务器上收到这个奇怪的错误:

 Error: Connection strategy not found
        at MongoStore (/Users/amills001c/WebstormProjects/lectal_all/manager/node_modules/connect-mongo/src/index.js:100:23)
        at Object.<anonymous> (/Users/amills001c/WebstormProjects/lectal_all/manager/app.js:42:12)
        at Module._compile (module.js:425:26)

我们正在使用带Express的Passport。

错误发生在以下代码段中的mongoose_connection: mongoose.connection行:

app.use(expressSession({
    secret: 'foobar',
    cookie: {
        secure: false,
        maxage: 1160000000,
        resave: true,
        saveUninitialized: true
    },
    store: new MongoStore({
        mongoose_connection: mongoose.connection   /*<== error happens here*/
    })
}));

这是什么错误,我该如何解决?

1 个答案:

答案 0 :(得分:8)

根据docs,我认为该行应该是:

store: new MongoStore({
    mongooseConnection: mongoose.connection
});

使用mongooseConnection代替mongoose_connection