S
S
Stanislav2018-11-14 17:06:31
MongoDB
Stanislav, 2018-11-14 17:06:31

Why does express-session store guest sessions, and how can we ignore the recording of such sessions?

The problem is the following.
Users often complained about the fact that the session flew quickly, increased the session storage period to 3 months and the database swelled up, don't worry, for example, in just one day, half a million documents in the db.sessions collection Normal
config

app.use(session({
    secret: 'secret',
    cookie: { path: '/', httpOnly: !0, maxAge: 7776000000, secure: 0 },
    name: 'sid',
    store: sessionStore,
    saveUninitialized: 0,
    resave: 0
}))

And sessionStore
const mongoose 			= require('mongoose')
    , expressSession 	= require('express-session')
    , MongoStore 		= require('connect-mongo')(expressSession)

    , sessionStore = new MongoStore({
        mongooseConnection: mongoose.connection,
        autoRemove: 		'interval',
        autoRemoveInterval: 1
    })

module.exports = sessionStore

I can’t understand why the express should store the guest / bot session, nothing is written to it, it just exists and no actions are taken with it, I mean the really necessary actions, or am I mistaken?
In fact, for authorization, I use the request.session.user check, where the guest is null, and the user is an object with data from the users collection.
I just don't see the point of making numerous unowned inserts into the database, why are they needed there? It is clear when a document contains an ID, but there are thousands of them, and there are millions of documents.
It would be desirable to achieve that session was stored in basis only of the user, and guest sessions.... for what they in general are necessary?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RidgeA, 2018-11-14
@RidgeA


and guest sessions .... what are they for at all
The guest can go to the site, add goods to the cart for 100500 million and sign up / log in before ordering.
Do not force him to collect the basket again.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question