connect-mongo MongoStore会话实际上是如何保存的?

die*_*lar 7 session mongodb node.js

我使用了实现会话Passport,但是为了存储我尝试connect-mongo使用mongoose连接的会话.

这是我的代码(会话部分):

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
    })
  }));
Run Code Online (Sandbox Code Playgroud)

我怀疑它是否适得其反的是app.use(connect.session({ secret: 'ilovescotchscotchyscotchscotch' })) is using连接模块,但MongoStore配置是在express-session变量上设置的.但是,首先删除会导致应用无法正常工作(不会进行身份验证/重定向).

所以,关于我的问题标题.该会话存储在哪里?我真的以为我可以去我的Mongo数据库找到任何存储它的集合.

如何在后端(Mongo)甚至在Java Script对象的应用程序中找到此类会话?

Pet*_*ons 10

connect-mongo默认情况下,会话存储在"sessions"集合中.它们应该存在于mongo shell或任何GUI工具(如robomongo)中.是的,它是默认创建的.我会传入mongooose_connection选项而不是db.

来自文档:

形式为mongoose_connection:someMongooseDb.connections [0]使用现有的mongoose连接.(可选的)

  • `store:new MongoStore({mongoose_connection:mongoose.connections [0]})` (2认同)