【发布时间】:2019-03-28 03:00:34
【问题描述】:
通过 findAndUpdateById 发送 put 请求,该请求在邮递员中返回 200 响应 - 但数据未更新。
put 请求是
app.put("/api/report/update/:id", (req, res) => {
Report.findByIdAndUpdate(
req.params.id,
req.body.data,
{ new: true },
(err, report) => {
if (err) return res.status(404).send({ message: err.message });
return res.send({ message: "report updated!", report });
}
);
});
发送的数据的形状是
report: {
month: "",
updateMajor: "",
updateMinor: "",
comments: {
comment1: "",
comment2: "",
comment3: ""
},
}
返回的数据与发送的完全相同。
感谢您的帮助。
【问题讨论】:
-
用
console.log(req.body)检查req.body中的内容,它很可能不包含您所期望的内容。