cuốn sách gpt4 ai đã làm

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

In lại Tác giả: Hồ Xil 更新时间:2023-11-01 09:53:42 26 4
mua khóa gpt4 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 thay vì foreingFieldlocalField 因为我需要使用 isDeleted: false 进行过滤可能还有其他匹配条件。

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

Cảm ơn!

26 4 0
Hồ Xil
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress