I'm learning to work with sessions and I need to somehow save them to the database (PostgreSQL). I am writing to nodejs using Express.

app.use( session({ secret:config.SESSION_SECRET, resave:true, saveUninitialized:true, cookie: {maxAge: 24 * 60 * 60 * 1000 }, store:new pgSession({ pg:pg, conString:"подключение к базе данных", tableName:"", maxAge: 24 * 60 * 60 }) }) ) 

So here. Should the table itself be created in PostgreSQL or is it automatically created somehow? For I watched the video, it was automatically created by a peasant in mongoDB ... And here I tried to create my own, this is how one column is missing, then another.

    1 answer 1

    I never connected PostgreeSQL to Node.js, but judging by the description, this module can help you. Dig up its sources, look at which tables are created by the connection module with the instruction


    And, as I see it, here are three fields that should be in the table:

     CREATE TABLE "session" ( "sid" varchar NOT NULL COLLATE "default", "sess" json NOT NULL, "expire" timestamp(6) NOT NULL ) WITH (OIDS=FALSE); ALTER TABLE "session" ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE; 
    • And which database do you work with? - danythere pm
    • Thank you, the error has disappeared, but the records are not saved: ( - danythere
    • I use mongodb, along with mongooze add-on - MiMEKiZ 6:02 pm