【发布时间】:2021-08-26 08:24:56
【问题描述】:
我正在处理酒店项目,但此功能无法正常工作。 我已经完全检查了 req.query.id 并且 req.body 正在传递它的值。它不会返回任何错误,但它根本不起作用
import Room from "../models/Rooms";
room = await Room.findByIdAndUpdate(req.query.id, req.body, ({
new: true,
runValidators: true,
useFindAndModify: false,
}));
注意: typeof(req.body) 返回一个字符串,当我尝试使用 JSON.parse 将其转换为数组时,它返回错误
{
"error": "Unexpected token } in JSON at position 54",
"success": false
}
req.query.id: 60c0582ca7a06d54682a7a4b
req.query.body: {
"pricePerNight":1000,
"internet": false,
}
【问题讨论】:
-
你能给我们看看 req.query.id 和 req.body
-
是的,我已经更新了它们