node.js - 如何在猫鼬的嵌入式文档中填充字段?
问题描述
我有一个类似这样的模型“帖子”
{
// Some other fields
comments: [
new mongoose.Schema({
content: {
type: String,
required: [true, "Content for a comment is required."],
},
author: {
type: mongoose.Types.ObjectId,
ref: "User",
required: [true, "Author for a comment is required."],
},
}),
}
在获取帖子后,我无法找到一种填充author
内部字段的方法。comment
我该怎么做?
解决方案
尝试跨多个级别填充
Post.find({ }).populate({
path: 'comments',
populate: { path: 'author' }
});
推荐阅读
- python - 如何突出显示geojson文件中的不同区域?
- angular - 如何使用 Angular Reactive Forms 动态检查单选按钮?
- python - 如何使用带有时间戳的 matplotlib.pyplot.xlim()?
- excel - 如何获取链接单元格的列号和行号
- c# - 在 Linux 上运行 Emgu.CV
- linux - bash 脚本跳过创建数据库创建
- php -
打印php字符串中第五个之前的字符 - sql - 使用一个主表 (SQL Server) 跨多个表将旧值更新为新值
- python - 将kivy设置重置为原始值
- ios - CocoaPods:无法构建 gem 原生扩展