0
出於某種原因,我正在嘗試更新通過在以下架構PUT請求字符串時出現以下錯誤:PUT請求給予強制轉換爲對象ID錯誤
`var mongoose = require("mongoose");
var litterSchema = new mongoose.Schema({
name: String,
image: String,
description: String
});
module.exports = mongoose.model("Litters", litterSchema);`
我很困惑,因爲我有似乎沒有問題的相同模式和路線。我想知道是否在我的一個依賴項中損壞了某些東西?不知道該去哪裏。
這裏是我的路線:
router.put("/:id", middleware.adminLoggedIn, function(req, res){
// req.body.litter on next line pulls from the square brackets on edit.ejs, this way don't have to define object here.
Litters.findByIdAndUpdate(req.params.id, req.body.litter, function(err, updatedLitter){
if(err){
res.send("ERROR");
} else {
res.redirect("/litters/" + req.params.id);
}
});
});
這裏是我得到的錯誤:
{ [CastError: Cast to ObjectId failed for value "http://cdn1-www.dogtime.com/assets/uploads/2011/01/file_23204_goldendoodle.jpg" at path "_id"]
message: 'Cast to ObjectId failed for value "http://cdn1-www.dogtime.com/assets/uploads/2011/01/file_23204_goldendoodle.jpg" at path "_id"',
name: 'CastError',
kind: 'ObjectId',
value: 'http://cdn1-www.dogtime.com/assets/uploads/2011/01/file_23204_goldendoodle.jpg',
path: '_id',
reason: undefined }
當你console.log(JSON.stringify(req.body.litter,null,4))''時,你會得到什麼? – chridam