You cannot use one aggregate()to execute two grouped counters with the desired result format. After the data has been grouped for the first time, when you no longer have the details necessary to create a second account.
A direct approach is to fulfill two queries, as you already do; -).
, , . _id _ .
mongo:
db.users.aggregate(
{ $group: {
_id: { group_name: "$group_name", status: "$status" },
'total_sum': { $sum: 1 }
}}
)
, , .
+ count, $addToSet .
. find(), group_name status, count .