1
新手添加條件在這裏,有沒有辦法在JS帆使用.populate時添加標準。或者甚至有可能這樣做?帆-的MongoDB在.populate
Ex。
Model.find().populate('toPopulate', {"toPopulate.toFind" : {$in: [1,2,3,4]}}).exec(console.log);
請一些線索
感謝
新手添加條件在這裏,有沒有辦法在JS帆使用.populate時添加標準。或者甚至有可能這樣做?帆-的MongoDB在.populate
Ex。
Model.find().populate('toPopulate', {"toPopulate.toFind" : {$in: [1,2,3,4]}}).exec(console.log);
請一些線索
感謝
@幾乎是正確的,只是需要mdunisch的答案,包括@ sgress454的修復。所以這裏是關於如何在填充中添加過濾器的工作示例。
Model.find().populate('toPopulate',
{where: {id: [1,2,3,4]}}).exec(console.log);
OR
你也可以不用where
Model.find().populate('toPopulate', {id: [1,2,3,4]}).exec(console.log);
嘗試:
Model.find().populate('toPopulate',
where: {
id: [1,2,3,4]
}
).exec(console.log);
這將是巨大的,如果你有一個鏈接到文件或東西,以便OP可以學習搜索。 – edi9999
感謝您的迴應,但它會在冒號部分之後給出錯誤。但無論如何感謝。 – avian
整個'where'子句需要用大括號包裹;那麼這應該工作。 – sgress454