I have updated my connect-mongo npm to the latest version 2.0.1 in node v8 its returning some error, if i comment the below code my projects works pretty well if not returning the below error

here is a bit of code

var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
        resave: true,
        saveUninitialized: true,
        secret: '6256346324',
        store: new MongoStore({
            db: global.db


.then(() => this.changeState('connected'))

TypeError: this.setCollection(...).setAutoRemoveAsync(...).then is not a function
    at MongoStore.handleNewConnectionAsync

modules used in package.json(i have listed only few)

connect-mongo": "^2.0.1",
    "express": "^4.16.2",
    "express-session": "^1.15.6",
    "mongodb": "^2.2.35"

so how can i solve this error?


As per your error it shows you have Express 4.16.2 and mongodb 2.2.35.

As per NPM Mongo Blog here you can check out the compatibility . As well as for connection integration of Express 4.x.

The sample connection code should be as mentioned below for Express 4.x, 5.0 and Connect 3.x:

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

    secret: 'foo',
    store: new MongoStore(options)

For further information see here and here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.