首页 > 解决方案 > 如何在具有特定 ID 的猫鼬模型上发表评论

问题描述

我创建了两个猫鼬模型:

var Post = new Schema({
name: String,
description: String,
address: String,
comments: [{ type: Schema.Types.ObjectId, ref: 'Comment' }],
phoneNum: { type: Number,
    unique: true }   

  });
   module.exports = mongoose.model("Post", Post);

      var Comment = new Schema({
     comments: { type: String }
    });
     module.exports = mongoose.model("Comment", Comment);

我试图弄清楚如何按 Id 为特定的 Post 文档发表评论,以及如何在我的 ejs 视图中呈现该文档的评论。我真的很感激任何帮助!

标签: mongooseejs

解决方案


推荐阅读