【发布时间】:2021-11-03 21:33:25
【问题描述】:
我是 mongoose 和 MongoDB 的新手,我有一个问题, 我想查找包含参考文献的文档。
我有 2 个这样的模型:
1: 引用类别的帖子:
const postsSchema = new Schema({
post_title: {
type: String,
required:true
},
post_categories: [{
type: Schema.Types.ObjectId,
ref: 'categories',
required:true
}],
});
2: 引用类别的类别
const categoriesSchema = new Schema({
categoryName: {
type: String,
required: true
},
categoryParent: {
type: Schema.Types.ObjectId,
ref: 'categoriesSchema',
}
});
我想查找所有具有父类别的帖子,例如(新闻),我试试这个:
Posts.find({'post_categories.categoryParent.categoryName': 'news'});
但我得到了一个空数组 []。 有没有办法找到包含参考文献的文档?
【问题讨论】: