robinfehr / sessionstore

Sessionstore is a node.js module for multiple databases. It can be very useful if you work with express or connect.
MIT License
54 stars 22 forks source link

timeout does not delete session stored in mongodb after the given time. #41

Open dev-aman-gupta opened 7 years ago

dev-aman-gupta commented 7 years ago

Hi,

I found a strange issue where the sessions are not timed out after the specified time.

app.use(session({
    secret: 'jwtsecret',
    resave:false,
    saveUninitialized:true,
    store: sessionstore.createSessionStore({
      type: 'mongodb',
      host: 'localhost',         // optional
      port: 27017,               // optional
      dbName: 'dbName',       // optional
      collectionName: 'sessions',// optional
      timeout: 10000             // optional
  })
}));

sessions are created correctly but are not timed out or deleted according to the given timeout. Can you please help here/

adrai commented 7 years ago

There is a Warning: Warning: The TTL index does not guarantee that expired data will be deleted immediately. There may be a delay between the time a document expires and the time that MongoDB removes the document from the database.

That's why I've introduced this: https://github.com/adrai/sessionstore/blob/master/lib/databases/mongodb.js#L213