【问题标题】:Passport.js and MongoStore error "Connection strategy not found at MongoStore"Passport.js 和 MongoStore 错误“在 MongoStore 找不到连接策略”
【发布时间】:2016-03-28 00:40:54
【问题描述】:

我的 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)

我们正在使用 Passport 和 Express。

错误发生在以下 sn-p 中的 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*/
    })
}));

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

【问题讨论】:

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


    【解决方案1】:

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

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

    使用mongooseConnection 而不是mongoose_connection

    【讨论】:

    • 谢谢,这可能成功了,奇怪,这曾经可以工作,但也许我碰到了新版本的护照/猫鼬/等
    • @AlexMills 这可能是问题所在,因为错误来自库。如果有什么,我很乐意提供帮助。
    猜你喜欢
    • 2016-12-13
    • 2013-10-27
    • 2016-04-21
    • 2021-08-07
    • 1970-01-01
    • 2013-09-23
    • 2014-01-07
    • 2014-10-17
    • 2014-08-18
    相关资源
    最近更新 更多