保存mongoose模型时更新会话数据

时间:2014-05-25 01:08:23

标签: javascript node.js express mongoose

我试图在mongoose save回调中更新快速会话数据。如何从第4行内访问(和更新)会话数据?

app.get('/', function(request, response){
  var model = new Model(somedata);
  request.session.ok = "ok";
  model.save(function (err, data) {
    request.session.ok = "won't save";
  });
});

app.get('/path', function(request, response) {
  console.log(request.session.ok);
  // returns 'ok'
});

1 个答案:

答案 0 :(得分:2)

您需要发送某种回复。例如:

app.get('/', function(request, response){
  var model = new Model(somedata);
  request.session.ok = "ok";
  model.save(function (err, data) {
    request.session.ok = "won't save";
    response.send(200);
  });
});