I am using "connect-mongo" node module to store session data in mongodb.
Below is my code related to configuring connect-mongo
const cookieParser = require('cookie-parser');
app.use(cookieParser());
const session = require('express-session');
const mongoStore = require('connect-mongo')(session);
app.use(session({
secret: "test",
store: new mongoStore({
url: mongodbURL,
collection : 'sessions',
autoRemove: 'interval',
autoRemoveInterval: 1 // In minutes. Default
}
}));
{
"_id": "EZ2sy6jHvnrlsyofqCrKVfPtp6hv5FX_",
"session": "{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"httpOnly\":true,\"path\":\"/\"},\"name\":\"mongosession\"}",
"expires": ISODate("2016-06-14T15:19:15.548Z")
}
cookie
property of connect-session
. By default, maxAge
is null
, making the cookie a (browser-)session cookie.ttl
property of connect-mongo
, which defaults to 14 days (which looks about right, judging by the timestamp in the expires
property). autoRemoveInterval
only configures how often connect-mongo
should check if there are any sessions that should expire.