我尝试安排从mongodb数据库中删除某个文档的作业,当我在执行请求后立即执行作业,但是,请求在1小时后删除文档(例如),它不会从数据库中删除。这是我的代码:
app.delete('logauth/removecourse/:uuid/:hours', isLoggedIn, function(req, res){
if(req.user.usertype == 1)
{
Teacher.findOne({ _id : req.user.teacher }, function(err, teacher){
if(err)
res.send(err);
var scheduled = schedule.scheduleJob(new Date(Date.now() + (req.params.hours * 3600000)), function(uuid, teach_id){
return function(){
Course.find({ _id : uuid, teacher : teach_id }).remove().exec(function(err){
if(err)
res.send(err);
});
}
}(req.params.uuid, teacher._id));
if(scheduled)
res.send(200);
else
res.send(500);
});
}
else
{
res.send(403);
}
});
关于我做错了什么的提示?
答案 0 :(得分:1)
我认为问题是您设置小时的方式,请检查:
app.delete('logauth/removecourse/:uuid/:hours', isLoggedIn, function(req, res){
if(req.user.usertype == 1)
{
Teacher.findOne({ _id : req.user.teacher }, function(err, teacher){
if(err)
res.send(err);
var d = new Date();
d.setHours(d.getHours()+1, d.getMinutes(), d.getSeconds());
var scheduled = schedule.scheduleJob(d, function(uuid, teach_id){
return function(){
Course.find({ _id : uuid, teacher : teach_id }).remove().exec(function(err){
if(err)
res.send(err);
});
}
}(req.params.uuid, teacher._id));
if(scheduled)
res.send(200);
else
res.send(500);
});
}
else
{
res.send(403);
}
});