gpt4 book ai didi

mongodb - $in 需要一个数组作为第二个参数

转载 作者:可可西里 更新时间:2023-11-01 09:53:42 26 4
gpt4 key购买 nike

<分区>

我正在尝试进行一些聚合,但遇到以下问题。我需要使用“管道”,当我要查找的数组丢失时出现错误。

{
$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'

因为不是所有的文档都有“comments”这个字段。

注意:我正在使用 pipeline 而不是 foreingFieldlocalField 因为我需要使用 isDeleted: false 进行过滤可能还有其他匹配条件。

是否只有在文档具有字段comments 时才进行此查找?

谢谢!

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com