'undefined is not a function' app.use NHibernate 中的会话错误,mongo 存储
' undefined is not a function' Error on app.use session in NHibernate, mongo store
我在 mongo 中有一个数据库,用于存储名为 'SessionStore' 的会话状态,以及一个名为 'Sessions' 的集合,用于存储会话状态。
我正在使用表达式会话来管理会话。
设置会话的代码如下;
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
.
.
.
var sessionDb = 'SessionStore';
var sessionCollection = ['Sessions'];
var mongojs = require('mongojs');
var ObjectId = mongojs.ObjectId;
var dbSessions = mongojs(sessionDb, sessionCollection);
.
.
.
app.use(session({
secret: 'mysessionsecret',
name: 'connectionEngine',
store: MongoStore({db: dbSessions}),
proxy: true,
resave: true,
saveUninitialized: true
}));
除了到达最后一行时失败并显示以下内容;
C:\Users\Paul\Documents\Visual Studio 2015\Projects\Connection-Engine\Connection-Engine\node_modules\connect-mongo\lib\c
onnect-mongo.js:126
self.emit(newState);
^
TypeError: undefined is not a function
at changeState (C:\Users\Paul\Documents\Visual Studio 2015\Projects\Connection-Engine\Connection-Engine\node_modules
\connect-mongo\lib\connect-mongo.js:126:12)
at MongoStore (C:\Users\Paul\Documents\Visual Studio 2015\Projects\Connection-Engine\Connection-Engine\node_modules\
connect-mongo\lib\connect-mongo.js:237:5)
at Object.<anonymous> (C:\Users\Paul\Documents\Visual Studio 2015\Projects\Connection-Engine\Connection-Engine\app.j
s:100:12)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.runMain [as _onTimeout] (module.js:501:10)
at Timer.listOnTimeout (timers.js:110:15)
我想我错过了部分设置,但我不确定是什么。任何人都可以提出一些建议。
最终调用不正确 - 需要创建 MongoStore 实例
app.use(session({
secret: 'w3happyf3ww3band0fbr0th3r5',
name: 'connectionEngine',
store: new MongoStore({db: 'SessionStore', collection: 'Sessions'}),
proxy: true,
resave: true,
saveUninitialized: true
}));
商店选项前面需要 'new'。
我在 mongo 中有一个数据库,用于存储名为 'SessionStore' 的会话状态,以及一个名为 'Sessions' 的集合,用于存储会话状态。
我正在使用表达式会话来管理会话。
设置会话的代码如下;
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
.
.
.
var sessionDb = 'SessionStore';
var sessionCollection = ['Sessions'];
var mongojs = require('mongojs');
var ObjectId = mongojs.ObjectId;
var dbSessions = mongojs(sessionDb, sessionCollection);
.
.
.
app.use(session({
secret: 'mysessionsecret',
name: 'connectionEngine',
store: MongoStore({db: dbSessions}),
proxy: true,
resave: true,
saveUninitialized: true
}));
除了到达最后一行时失败并显示以下内容;
C:\Users\Paul\Documents\Visual Studio 2015\Projects\Connection-Engine\Connection-Engine\node_modules\connect-mongo\lib\c
onnect-mongo.js:126
self.emit(newState);
^
TypeError: undefined is not a function
at changeState (C:\Users\Paul\Documents\Visual Studio 2015\Projects\Connection-Engine\Connection-Engine\node_modules
\connect-mongo\lib\connect-mongo.js:126:12)
at MongoStore (C:\Users\Paul\Documents\Visual Studio 2015\Projects\Connection-Engine\Connection-Engine\node_modules\
connect-mongo\lib\connect-mongo.js:237:5)
at Object.<anonymous> (C:\Users\Paul\Documents\Visual Studio 2015\Projects\Connection-Engine\Connection-Engine\app.j
s:100:12)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.runMain [as _onTimeout] (module.js:501:10)
at Timer.listOnTimeout (timers.js:110:15)
我想我错过了部分设置,但我不确定是什么。任何人都可以提出一些建议。
最终调用不正确 - 需要创建 MongoStore 实例
app.use(session({
secret: 'w3happyf3ww3band0fbr0th3r5',
name: 'connectionEngine',
store: new MongoStore({db: 'SessionStore', collection: 'Sessions'}),
proxy: true,
resave: true,
saveUninitialized: true
}));
商店选项前面需要 'new'。