connect-mongo 不适用于共享 mongo 集群。我们在我们的应用程序中添加了“connect-mongo”:“^0.8.2”模块,添加了以下配置详细信息。
"mongoStore": {
"url" : "user:password@server1:27400/zeta-sessions,server2:27400/zeta-sessions,server3:27400/zeta-sessions",
"name" : "web-app",
"secret": "secret",
"cookie": {
"path": "/",
"httpOnly": true,
"maxAge": 31556952000 // 1 year
},
"options" : {
"server": { "poolsize": 5 }
,"replset": {"rs_name": "zeta-po"}
},
"resave": true,
"saveUninitialized": true,
"store": null // NB: this will be overlaid in our module
}
还 ,
// ./lib/mongo-session.js
'use strict';
var session = require('express-session'),
MongoStore = require('connect-mongo')(session);
/** Creates a Mongo-backed session store.
*
* @param {Object} [config] Configuration options for express-session and connect-mongo
* @returns {Object} Returns a session middleware which is backed by Mongo
*/
module.exports = function (config) {
// add the 'store' property to our session configuration
config.mongoStore.store = new MongoStore(config.mongoStore);
// create the actual middleware
return session(config.mongoStore);
};
执行服务时出现以下错误。
Possibly unhandled Error: Required MongoStore option `db` missing or is not a string.
at buildUrlFromOptions (/app/home/appjs/zeta-demo/node_modules/connect-mongo/lib/connect-mongo.js:163:15)
at new MongoStore (/app/home/appjs/zeta-demo/node_modules/connect-mongo/lib/connect-mongo.js:250:7)
at module.exports (/app/home/appjs/zeta-demo/web/lib/mongo-session.js:14:31)
at resolveImpl (/app/home/appjs/zeta-demo/node_modules/kraken-js/node_modules/meddleware/index.js:98:20)
at resolve (/app/home/appjs/zeta-demo/node_modules/kraken-js/node_modules/meddleware/index.js:53:18)
at register (/app/home/appjs/zeta-demo/
请分享你的想法。