我正在努力为MongoDB数据库创建汇总查询。
这是我的输入数组
recipients = [1,2,7]
这是我的数据库集合
{
"chapter": 1,
"targets": [
{
type: 'user',
recipient: 1
}
]
},
{
"chapter": 1,
"targets": [
{
type: 'user',
recipient: 2
}
]
},
{
"chapter": 2,
"targets": [
{
type: 'user',
recipient: 3
}
]
},
{
"chapter": 3,
"targets": [
{
type: 'user',
recipient: 4
}
]
},
所需的输出
should be [] because 7 doesn't exist in targets.recipient in the collection
这是我到目前为止尝试过的
db.collection.aggregate([
{
$match: {
'targets.recipient': { $in: recipients },
},
}
])
任何建议,谢谢。