我有几个看起来像这样的文档(减去许多其他不相关的字段):
[{
status: 'open',
createdDate: 2021-06-17T09:02:58.325Z
},
{
status: 'declined',
createdDate: 2021-07-25T09:09:15.851Z
},
{
status: 'declined',
createdDate: 2021-09-22T09:32:14.958Z
},
{
status: 'open',
createdDate: 2021-09-02T09:45:26.584Z
},
{
status: 'referral',
createdDate: 2021-09-05T09:46:02.764Z
}]
对于集合的这个子组,我想汇总下一个结果:
{
"2021-06" : { submitted: 1, referral: 0, declined: 0},
"2021-07" : { submitted: 1, referral: 0, declined: 1},
"2021-08" : { submitted: 0, referral: 0, declined: 0},
"2021-09" : { submitted: 3, referral: 1, declined: 1},
}
提交的文件总数(打开、推荐和拒绝)。我尝试以多种方式使用 $group ,但没有成功。有什么建议么?谢谢!