在 monk 的 findOne 命令中创建会话

Creating session within monk's findOne command

这段简单的代码说明了问题:第二个会话没有保存。我怎样才能完成这项工作?

router.post('/users/login', function (req, res) {

 var db = req.usersDb;
 var users = db.get('users');

 req.session.test = "This works";
 req.session.save();

 users.findOne({ username: req.body.username}).on('success', function (doc) { 
        console.log(doc.email); //this works
        req.session.email = doc.email; //This not working
        req.session.save(); 
 });

});

将选项对象中的 express-session 'resave' 属性 更改为 false 解决了问题。

示例:

app.use(session({ genid: function(req) { return guid() }, secret: 'secret', resave: false, saveUninitialized: true }))