这是我的代码段
Punch.findOne({Employee: id, Date: thisDate}).exec(function (err,model) {
if(err)
{
console.log(err);
}
else
{ var date = new Date();
var thisTime = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds().toString();
model.Out=thisTime;
model.save(function(err){
if (err) {
req.session.pStatus="failed";
res.view('Person/punch/');
}else {
Person.findOne(id).exec(function(err,emp) {
emp.Punched='No';
emp.save(function(err){ console.log(err)});
req.session.punch=emp.Punched;
req.session.pStatus="Punched Out at "+thisTime;
res.render( 'Person/punch',{'model':emp});
});
}
});
}
});
此处model.save()
仅通过更新时间值运行一次。在以后的函数调用中,它不会更新生成的时间值