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
}
}));
Once a user connects to root "/" url from browser, a record is getting inserted in database
{
"_id": "EZ2sy6jHvnrlsyofqCrKVfPtp6hv5FX_",
"session": "{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"httpOnly\":true,\"path\":\"/\"},\"name\":\"mongosession\"}",
"expires": ISODate("2016-06-14T15:19:15.548Z")
}
My questions are
why is that originalMaxAge , expires keys of "session" are null and what needs to be modified so that these keys have a value.?
Since I have set autoRemoveInterval to 1 min , I was assuming that session values from database will be removed in 1 min , but that was not the case What needs to be modified to achieve that ?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.