【发布时间】:2021-02-13 08:41:32
【问题描述】:
我正在尝试在 mongodb 中执行查找以从两个表中获取数据。这是我到目前为止创建的内容:
database.collection('surveys').aggregate([
{ $lookup:
{
from: 'questions',
localField: '_id',
foreignField: 'surveyId',
as: 'questions'
}
}
]).toArray(function(err, res) {
if (err) throw err;
console.log(JSON.stringify(res));
});
问题是我的调查表中的数据显示得很好,但我的问题表中的数据总是一个空数组,我不知道为什么。请在附件中找到我的数据库结构的两个屏幕截图。
【问题讨论】:
标签: node.js mongodb lookup aggregation