amount of documents =/= amount of users
milanwdewaele opened this issue · 2 comments
hi.
i have a project where 10 people have access to. however after a while there were 2.5k documents inside the collection it needs.
and after refreshing they just keep on coming. did i do something wrong in my code?
var store = new MongoDBStore({
uri: process.env.MONGO_URL,
collection: 'v2Sessions'
});
app.use(session({
name: "Auth",
secret: process.env.SESSION_SECRET_KEY,
resave: true,
saveUninitialized: true,
cookie: {
maxage: 86400000
},
store: store
}));
kind regards
milan
Whenever someone connects to your website, a session is created and assigned to them. Since you have saveUninitialized: true set, it will save all these empty sessions to the database. You should set saveUninitialized: false so that sessions will only be saved when it's user has logged in.
See https://www.npmjs.com/package/express-session#saveUninitialized for more information.
@wfjake is right, a session isn't one-to-one to a user. And refreshing the page would create a new session if saveUninitialized: true is set.