mongodb-js / connect-mongodb-session

Lightweight MongoDB-backed session store for Connect and Express
Apache License 2.0
176 stars 35 forks source link

when are sessions deleted from the database? #88

Open evanholt1 opened 4 years ago

evanholt1 commented 4 years ago

i am using express-session & this package, and this is my test setup: ` let sessionStore = new MongoDBStore({ uri: process.env.DB_HOST, collection: 'sessions', expires: 1, });

app.use(session({ secret: process.env.SECRET, store: sessionStore, resave: false, saveUninitialized: false, unset: "destroy", cookie: { maxAge: 1 }, name: "US" // User Session })); ` yet when i run a GraphQL mutation which adds an "_id" field to 'req.session', while the cookie doesnt appear on client-side(it lasts a millisecond), a session is created on the database, and lasts a dynamic amount of time (lasting from 1 second to a minute) while i would expect it to expire in 1 millisecond, then destroyed from the database. what is the explanation of this? what am i missing?

nickgarver commented 3 years ago

mongo expireAfterSeconds / TTL only runs every 60 seconds. even if it expired it would still take whatever time is remaining in the 60 second window to delete the entry (i.e. 30ish seconds if it expires immediately)