mongoose - 如何在具有特定 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 视图中呈现该文档的评论。我真的很感激任何帮助!
解决方案
推荐阅读
- ms-access - MS Access VBA 和宏导出
- javascript - 使用 TestCafe Selector 或 testcafe-react-selector 为嵌套组件查找元素节点时遇到问题
- c++ - C++ 无法使用嵌套循环索引数组的元素
- sql - 尽管获得了 GRANT EXECUTE,但我在函数调用中得到“ORA-00904:无效标识符”
- javascript - 需要将客户价值传递回 React 中的 POST 操作
- c++ - gtest 单元测试目标配置文件路径
- xamarin - 无法从“Xamarin.Forms.Entry”转换为“Tweetinvi.Models.IUserIdentifier”
- java - RestTemplate JSON 反序列化
- bash - 从 jenkins 调用的 Minicom 脚本在退出 '! killall -9 minicom'
- hibernate - 强制不在杰克逊中序列化未获取的惰性对象