{
"169v55": [
{
"code": "2001",
"active": true,
"delist": false
}
],
"SLO1019jkf": [
{
"code": "MOUNTY2026",
"active": false,
"delist": false,
"createdAt": "2019-12-26T15:36:51.819Z"
},
{
"code": "MOUNTY2027",
"active": false,
"delist": false,
"createdAt": "2019-12-26T16:25:32.437Z"
},
{
"code": "MOUNTY2054",
"active": false,
"delist": false,
"createdAt": "2020-02-17T05:47:28.558Z"
}
]
}
上面的结果是我替换 newRoot 后得到的。这是我的分组代码,上面给出了结果
{
$group: group
},
{
$project: {
doc: "$doc",
date: date,
type: type
}
},
{
$group: {
_id: null,
locations: {
$push: {
k: "$_id",
v: "$doc"
}
}
}
},
{
$replaceRoot: {
newRoot: {
$arrayToObject: "$locations"
}
}
}
现在我需要再次与 active 和 delist 分组。所以,我想要的输出如下
{
"169v55": {
active: 1,
inactive: 2
},
"SLO1019jkf": {
active: 0,
inactive: 3
}
}
以上{ active: 1, inactive: 2 }
表示总数active
和inactive
文档各自数组的计数。