connect-mongo vs connect-mongodb-session: managing expiring sessions
DarkLite1 opened this issue · 2 comments
I was comparing both stores to see which one fits the best for our needs. In simple terms, we just want to set a store that connects to the mongodb database and have it manage everything.
By this, we also mean the clean-up of old/unused/obsolete sessions, or data, in the database collection. This to avoid an ever growing db size. I found information on this in the readme of connect-mongo but not in yours.
Another question I have is wheter it would be better to start a new db connection as required by your module:
The MongoDBStore class has 3 required options:
uri: a MongoDB connection string
databaseName: the MongoDB database to store sessions in
collection: the MongoDB collection to store sessions in
Or simply reuse the current connection as is possible with connect-mongodb?
I'm a real newbie in all this so any help or direction in why/what would be appreciated. The main reason I came to have a look here is because this is maintained by the same developpers as mongodb itself, so we would expect better/longer support in case of updates to the db, and because the intro mentions it is meant to e be replacement for connect-mongodb-session.
Thank you for the clarification.
I was also comparing both stores and I'm also wondering which package to use.
connect-mongo gives the possibility to use an existing instance of MongoDB and it would be interesting if connect-mongodb-session adds this possibility.
By default, this module deletes sessions after 2 weeks. You can configure this using the expires option:
const store = new MongoDBStore({
uri: 'mongodb://localhost:27017/connect_mongodb_session_test',
collection: 'mySessions',
expires: 1000 * 60 * 60 * 24 * 30 // 30 days in milliseconds
});