jdesboeufs / connect-mongo

MongoDB session store for Express

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] How does `autoRemove: 'native'` work?

Hawmex opened this issue · comments

  • I'm submitting a ...
    [ ] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [x] question about how to use this project

  • Summary
    How does autoRemove: 'native' work? I'm using Passport and I'm wondering how much time after a user logs out, their session is deleted from my mongoDB? Does it even work this way?

  • Other information
    none

@Hawmex As you can see from the source code. It use the MongoDB native TTL index to expire items base on expires field. And the field itself is base on the ttl set in the option.
https://github.com/jdesboeufs/connect-mongo/blob/master/src/lib/MongoStore.ts#L226

@mingchuno Ah, you mean the session is automatically deleted by MongoDB when the date specified in its expires field has come?

@mingchuno Ah, you mean the session is automatically deleted by MongoDB when the date specified in its expires field has come?

Yes. Here’s the explanation: https://docs.mongodb.com/manual/core/index-ttl/

Take note that there may be a small delay before MongoDB manages to delete outdated session, depending on database load

Thanks @schamberg97. It got cleared up to me.