Skip to main content

TypeError: Class constructor MongoStore cannot be invoked without 'new'

 This error occurs as because may be you have used the following code: 

const MongoStore= require('connect-mongo')(session);

and

app.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: false,
    store: new MongoStore({ mongooseConnection: mongoose.connection })
}));


Now this is happening as because syntax have been changed (see the documentation here: documentation)


Solution that worked for me: 

Use this: 

const MongoStore= require('connect-mongo');


and, 

app.use(session({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: false, //false means don't create a session untitl it is stored
    // store: new MongoStore({ mongooseConnection: mongoose.connection })
    store: MongoStore.create({
        mongoUrl: process.env.MONGO_URI
    })
}));




Comments

Popular posts from this blog