Search code examples
mongodbexpresssession-storage

Connect-mongo not creating database


I have the following code to set up a session store with connect-mong

 var express = require('express');
 var MongoStore = require('connect-mongo')(express);
 var app = express();

app.use(express.cookieParser());
app.use(express.session({
secret: '1234567890QWERTY',
maxAge: new Date(Date.now() + 3600000),
store: new MongoStore({
    db: 'mydb',
    host: '127.0.0.1'
}),
 cookie: { maxAge: 24 * 60 * 60 * 1000 }
}));

In the requests and responses from the server I can see the sessionIDs, but the database is not created or if I create it the session collection does not gets filled. I do not receive any errors on the console.

I cannot find what am I missing ( using express 3).


Solution

  • I had multiple use of the session and cookieParser. This caused the problem.