Schema 和 Model 没问题,Mongoose .populate 不工作

Schema and Model are ok and Mongoose .populate not working

我从终端检查了我的数据库,数据没问题,但是填充时 'commnets' 仍然给我 ID

这是我展示数据的路线

var camp_id= req.params.id ;
Campground.findById(camp_id).populate("commnets").exec(function(err,fcg){
    if(err) { console.log(err) ;}
    else {
        console.log("No err") ;
        console.log(fcg) ;
        res.render("show",{campground: fcg});}


}) ;

moongose 模式(露营地和评论)

var campgroundSchema = new mongoose.Schema( {
name: String ,
image: String ,
description : String ,
comments: [
    {
        type: mongoose.Schema.Types.ObjectId,
        ref: "Commnet"
    }
 ]
 } ) ;

var Campground = mongoose.model("Campground",campgroundSchema);

var commentSchema = new mongoose.Schema({
text: String ,
aurthor: String
}) ;

var Comment = mongoose.model("Commnet",commentSchema) ;

我认为这是因为拼写错误。你需要使用 "comments" 而不是 "commnets"

var camp_id= req.params.id ;

Campground.findById(camp_id).populate("comments").exec(function(err,fcg){
    if(err) { console.log(err) ;}
    else {
        console.log("No err") ;
        console.log(fcg) ;
        res.render("show",{campground: fcg});}


}) ;