我只想看看我有多少人拥有特定的区块 ID。在按块 ID 过滤数组后,我尝试对“bot_survey”进行分组,但我无法获得正确的结果。这是我的 2 条记录
{
date: '2019-06-13',
blocks:[
{
block_id: '5caf27cfcb4b530e4d51bb72',
triggered_by:[
{
person_id: '2342'
},
{
person_id: '436'
}
]
}
]
},
{
date: '2019-06-14',
blocks:[
{
block_id: '5caf27cfcb4b530e4d51bb72',
triggered_by:[
{
person_id: '2342'
},
{
person_id: '965'
}
]
}
]
},
这是我的查询
db.getCollection('analytics').aggregate([
{$match: {date: {$lte: '2019-06-13'},"blocks.block_id": '5caf27cfcb4b530e4d51bb72'}},
{
$project: {
date: 1,
bot_survey: {
$filter: {
input: "$blocks",
as: "blocks",
cond: { $eq: [ "$$blocks.block_id", '5caf27cfcb4b530e4d51bb72' ] }
}
}
}
},
{
$group: {
_id: {date: "$bot_survey.triggered_by.person_web_id"},
}
}
])
但我需要一个类似的结果
{
person_id: '2342',
person_id: '436',
person_id: '965'
}
所以我可以计算结果。我怎样才能做到这一点?