Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passport.js and MongoStore error "Connection strategy not found at MongoStore"

I am getting this strange error on my Node.js server:

 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)

We are using Passport with Express.

The error is happening at the line mongoose_connection: mongoose.connection in the following snippet:

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

What is this error and how can I fix it?

like image 787
Alexander Mills Avatar asked Jan 07 '23 23:01

Alexander Mills


1 Answers

According to docs, I believe that line should be:

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

Use mongooseConnection instead of mongoose_connection.

like image 121
Aᴍɪʀ Avatar answered Jan 09 '23 19:01

Aᴍɪʀ