How are connecto-mongo MongoStore sessions actually saved?

I implemented sessions using Passport , but to store sessions I tried connect-mongo using mongoose . p>

This is my code (part of the session):

 var express = require('express') var mongodb = require('mongodb') var mongoose = require('mongoose') var bodyParser = require('body-parser') var cookie = require('cookie-parser') var connect = require('connect') var passport = require('passport') //var flash = require('connect-flash') var session = require('express-session'); var MongoStore = require('connect-mongo')(session); var LocalStrategy = require('passport-local').Strategy; var app = express() var BSON = mongodb.BSONPure app.use(express.static(__dirname+"/public")) app.use(bodyParser()) app.use(cookie()) app.use(connect.session({ secret: 'ilovescotchscotchyscotchscotch' })); app.use(passport.initialize()); app.use(passport.session()); mongoose.connect('mongodb://localhost/psicologosTuxtepecDB') var Schema = mongoose.Schema var userCredential = new Schema({ username: String, password: String }, { collection: 'members' }) var userCredentials = mongoose.model('members', userCredential) app.use(session({ secret: 'ziKologiia', clear_interval: 900, cookie: { maxAge: 2 * 60 * 60 * 1000 }, store: new MongoStore({ db : mongoose.connection.db }) })); 

Something I doubt would be counterproductive that the module app.use(connect.session({ secret: 'ilovescotchscotchyscotchscotch' })) is using connect, but the MongoStore configuration is set to the express-session variable. However, removing the first reason does not work well (will not authenticate / redirect).

So, about my question title. Where is this session stored? I really thought I could go to my Mongo database and find any collection that stores it.

How can I find such sessions in the backend (Mongo) and even when using Java Script objects?

+6
source share
2 answers

connect-mongo stores sessions in the default sessions collection. They should be there and visible in the mongo shell or in any graphical tool such as robomongo. Yes, it is created by default. I would switch to the mongooose_connection option instead of db .

From the docs:

mongoose_connection in the form: someMongooseDb.connections [0] to use an existing mongoose connection. (Not necessary)

+8
source

One thing you have to do is replace

 app.use(connect.session({ secret: 'ilovescotchscotchyscotchscotch' })); 

via

 app.use(session({ secret: 'ziKologiia', clear_interval: 900, cookie: { maxAge: 2 * 60 * 60 * 1000 }, store: new MongoStore({ db: mongoose.connection.db }); })); 
+3
source

Source: https://habr.com/ru/post/969620/


All Articles