我尝试在填充后查找查询。我有一本书和作者模型。在数据访问中,我将年份提交给book.find()查询。我在书中填充了作者,但由于发送了数年,所以无法得到答复。所有藏书归还。但是回应应该是书籍,并且在提交的书籍中应该填写作者,并且应该填写作者。
像这样的书模型:
const Book = new Schema({ 作者:[{type:Schema.Types.ObjectId,ref:'Author'}], 还有另一个领域 )};
像这样的作者模型:
const Author = new Schema({ 年:{类型:数字}, 还有另一个领域 )};
我尝试过这样:
find.book({})
.populate({
path: 'authors',
match: {
year: $in { years }
}
});
我也这样尝试过
find.book({})
.populate('authors', null, { year: $in { years } });
他们没有满足我的要求。
例如,我想要这样的响应:
{
book{
authors:[
{
_id: "Author A,
year: 1990,
},
{
_id: "Author B",
year: 1990,
}
],
...another fields of book
}
}
我该怎么办?