出现错误"/>
如何在Mongodb中转换ObjectId?我尝试了不同的方法,但是仍然出现错误
模式
//模式设置
var campgroundSchema = new mongoose.Schema({
name: String,
image: String,
description: String
})
var campground = mongoose.model("campground", campgroundSchema)
#The error is where coming from here, don't seem to get the campgrounds diplayed
app.get("/campgrounds/:id", function(req, res){
//find the campground with provided ID
campground.findById(req.params.id, function(err, foundCampground){
if(err){
console.log(err)
} else {
//render show template
res.render("show", {campground: foundCampground})
}
})
})
错误消息
**消息:'在模型“营地”的路径“ _id”处,对值“ 5e61150b58e80830240ef790”的对象ID投放失败,名称:“ CastError”,模特:模特{营地}} **
回答如下:创建这样的架构时,您可以传递{ _id: false }
var campgroundSchema = new mongoose.Schema({
name: String,
image: String,
description: String
}, { _id: false })
更多推荐
如何在Mongodb中转换ObjectId?我尝试了不同的方法,但是仍然出现错误
发布评论