我有一個模式concerts,我reviews使用虛擬填充來填充它,它回傳一組評論。現在,在每條評論中,我都必須再次填充customerId它的nameand avatar。
這是我的代碼
const populateReviews = await Concert.findById(id).populate({
path: "reviews",
options: {
sort: { rating: -1, updatedAt: -1 },
},
});
const populateCustomers = await Customer.populate(populateReviews, {
path: "reviews.customerId",
options: {
select: { name: 1, avatar: 1 },
},
});
這是上面代碼的輸出。

我必須填充customerId。請幫我解決一下這個。
uj5u.com熱心網友回復:
跨多個級別填充將幫助您
Concert
.findById(id)
.populate({
path: "reviews",
options: {
sort: { rating: -1, updatedAt: -1 },
},
populate : {
path : 'customerId',
options: {
select: { name: 1, avatar: 1 },
},
}
})
.exec(function (err, res) {
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/459373.html
下一篇:具有限制大小的MongoDB值集
