我的代码以60秒到2分钟的间隔一次又一次地运行。这个put函数需要能够动态地从多个数组中提取数据。我把它缩小到只发生在服务器端,客户端的功能永远不会触发,但服务器端将继续运行。任何人都知道为什么会发生这种情况?我尝试了'update','findByIdAndUpdate'和'findById'都得到了相同的结果。
router.put('/updateDeleteProducts', function(req, res, next){
console.log("Here is the delete info: ", req.body);
var size = req.body.size;
var pictures = req.body.picture;
var outerfabric = req.body.outerfabric;
var innerfabric = req.body.innerfabric;
var armlength = req.body.armlength;
var backlength = req.body.backlength;
var updates = {
$pull: {updated:true}
};
if (req.body.size != undefined){
updates.$pull.size = size;
}
if (req.body.picture != undefined){
updates.$pull.pictures = pictures;
}
if (req.body.outerfabric != undefined){
updates.$pull.outerfabric = outerfabric;
}
if (req.body.innerfabric != undefined){
updates.$pull.innerfabric = innerfabric;
}
if (req.body.armlength != undefined){
updates.$pull.armlength = armlength;
}
if (req.body.backlength != undefined){
updates.$pull.backlength = backlength;
}
console.log("Here are the variables to be deleted: ", updates);
Products.update({_id: req.body._id}, updates, function(err, data){
if (err) next(err);
console.log("DELETE Callback Data: ",data);
});
});
答案 0 :(得分:0)
因为您没有结束您的回复。由于您使用的是Express,因此应在res.send()
回调中调用end
(或在您的响应中调用Products.update
事件的其他方法)。试试这个:
Products.update({_id: req.body._id}, updates, function(err, data){
if (err) next(err);
console.log("DELETE Callback Data: ",data);
res.send(data);
});