我想使用邮递员发送删除请求。但我收到此错误消息
{
"status": "fail",
"message": "Cast to ObjectId failed for value \"feedback\" at path \"_id\" for model \"User\"",
"error": {
"stringValue": "\"feedback\"",
"kind": "ObjectId",
"value": "feedback",
"path": "_id",
"reason": {},
"message": "Cast to ObjectId failed for value \"feedback\" at path \"_id\" for model \"User\"",
"name": "CastError",
"statusCode": 500,
"status": "fail"
}
}
这是我的删除请求
exports.deleteFeedback = catchAsynsc(
async (req, res, next) => {
console.log(req.params);
const deletefeedback = await feedback.findByIdAndRemove(req.params.id);
res.status(200).json({
status: 'success',
data: deletefeedback
})
}
);
请帮助我找到解决方法!
答案 0 :(得分:0)
您需要将'req.params.id'作为'ObjectId'
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;
var objId = new ObjectId(request.params.Id);