簡體   English   中英

貓鼬填充一批數組

[英]Mongoose populating batch of arrays

我有一個架構,其中包含子文檔中的人口參考。

var schema = new mongoose.Schema({
    references: {
        images: [{ref: 'Page', type: mongoose.Schema.Types.ObjectId}],
        files: [{ref: 'Page', type: mongoose.Schema.Types.ObjectId}]
    }
});

然后為其創建一個模型,使其與引用的名稱匹配(頁面=>頁面)。

var Page = mongoose.model('Page', schema);

我想通過其標識符檢索頁面並檢索所有引用。

Page.findById(id)
    .populate('references.images') // Err.. two populations..
    .populate('references.files') // Err.. two populations..
    .exec(function(err, page) {
    // ... snip ...
});

現在我正在做多個人口。 如何確保單個填充加載一批陣列?

從3.6預發行版開始,可以執行以下操作:

Page.findById(id)
    .populate('references.images references.files')
    .exec(function(err, page) {
    // ... snip ...
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM