【发布时间】:2019-06-27 18:15:44
【问题描述】:
我正在尝试进行一些聚合,但遇到以下问题。我需要使用“管道”,当我要查找的数组丢失时出现错误。
{
$lookup: {
from: 'comments',
let: { comments: '$comments' },
pipeline: [
{
$match: {
$expr: {
$in: ['$_id', '$$comments']
},
isDeleted: false
}
}
],
as: 'comments'
}
}
在这个阶段我收到以下错误:
'$in requires an array as a second argument, found: missing'
因为并非所有文档都有“cmets”字段。
注意:我使用 pipeline 而不是 foreingField 和 localField 因为我需要使用 isDeleted: false 和其他匹配条件进行过滤.
是否只有在文档具有字段 cmets 时才进行此查找?
谢谢!
【问题讨论】:
标签: mongodb mongoose mongodb-query aggregation-framework