猫鼬连接
var db = mongoose.connect(config.db.uri, {
auth: {
user: config.db.options.user,
password: config.db.options.pass
},
},function (err) {
//Log Error
if (err) {
console.error(chalk.red('Could not connect to MongoDB!'));
console.log(err);
} else {
// Enabling mongoose debug mode if required
mongoose.set('debug', config.db.debug);
console.log(db);
// Call callback FN
if (cb) cb(db);
}
});
MongoStore
/**
* Configure Express session
*/
module.exports.initSession = function (app, db) {
// Express MongoDB session storage
app.use(session({
saveUninitialized: true,
resave: true,
secret: config.sessionSecret,
cookie: {
maxAge: config.sessionCookie.maxAge,
httpOnly: config.sessionCookie.httpOnly,
secure: config.sessionCookie.secure && config.secure.ssl
},
key: config.sessionKey,
store: new MongoStore({
mongooseConnection: db.connection,
collection: config.sessionCollection
})
}));
};
我总是在控制台上不断找到未找到连接策略,尝试了所有可能的方法,但无法解决此问题。
软件包版本 “ mongo-connect”:“ 2.1.0”, “猫鼬”:“ ^ 5.3.3”, “表达”:“ ^ 4.13.1”, “ express-session”:“ ^ 1.11.3”,
如果有人解决了此问题,请提供帮助