【发布时间】:2020-12-01 11:09:57
【问题描述】:
我想在 Plan Schema 上运行聚合并获取具有引用 ID planId 的反馈。
但是,如果我想填充查找,我需要 Plan 中的参考 ID,但我不喜欢这种保存参考 ID 的策略,我喜欢将所有内容分开。
有什么方法可以在没有参考 ID 的情况下进行填充。
类似的东西。但它不起作用。
const pipe = [
{
$lookup: {
from: 'Feedbacks',
pipeline: [
{
$match: {
planId: '$_id'
}
}
],
as: 'feedback'
}
}]
await Plan.aggregate(pipe);
export interface Plan {
_id: ObjectId;
...
}
export interface Feedback {
planId: ObjectId;
...
}
【问题讨论】:
标签: node.js mongoose aggregation mongoose-populate