Sessions collection is too big
See original GitHub issueI installed connect-mongo
a few days ago now to store my express-session
s in my DB. Today I checked my sessions collection and found out that there were more than 200,000 documents in there! I tried deleting my collection and waiting 60 seconds, and there were already 200 documents in there.
Why are documents being resaved even though I have resave
set to false
? It seems as if documents are being saved endlessly…
Here is my current configuration:
app.use(session({
secret: config.secret,
resave: false,
saveUninitialized: false,
unset: 'destroy',
store: new MongoStore({
mongooseConnection: mongoose.connection,
touchAfter: 3600, //Restore once every hour
autoRemove: 'interval',
autoRemoveInterval: 60 //Remove after one hour
})
}));
At most I would only have around 3 users using my app at the moment.
I contacted connect-mongo
and they stated that it would have to be an issue with express-session
.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
node.js - Sessions collection too big in a MEAN app. Is it okay to ...
I'm making changes to an old MEAN app and just found out that the sessions collection is huge (more than 38 million records)....
Read more >huge number of updates on system.sessions collection
When a user creates a session on a mongod or mongos instance, the record of the session initially exists only in-memory on the...
Read more >How should I handle session files that become too numerous?
@davidalger - PHP's own garbage collection operates via cron. It simply find s all files older than sess.gc_maxlifetime and removes them. Deleting sessions...
Read more >Large Session Size Causing Sitecore Redis Timeouts, Identify ...
Identifying a data size issue is quite simple once you have the prerequisites in place. Specifically, you need access to a Redis CLI...
Read more >MongoDB Limits and Thresholds
This document provides a collection of hard and soft limitations of the MongoDB ... option to allow for the migration of ranges that...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@romeboards , you also need ton use
saveUninitialized: false
, notsaveUninitialized: true
in your code, otherwise everything that hits your server, event assets, will keep creating a new session. If you are usingtrue
, then what you are experiencing is expected…@zilions From your first post you mention that you’ve got 200 documents after 60 seconds. Thats about 3 requests a second. That seems like quite a few for only 3 users. Do you log all requests? If you are getting that many requests, then somewhere in your code you are probably touching the session for each request even though you aren’t intending to use it. Based on previous issues I’ve seen, this is potentially happening in the
jwt
script you mention. But, I have no way to know that without grepping around your code. If you aren’t getting 3 requests/second, then something other thanexpress-session
is likely the culprit.Either way, I wouldn’t think the indexes you have set on the collection have anything to do with the issue.