db.COLLECTION_NAME.aggregate([
{$project:{
"arr": {$objectToArray:"$$ROOT"},
}},
{$unwind: "$arr"},
{$project: {
"_id": 0,
"k": "$arr.k",
}},
{$group: {
"_id": { "k": "$k" },
"f": {$sum: NumberInt(1)},
}},
{$project: {
"_id": 0,
"k": "$_id.k",
"f": 1,
}},
{$sort: {
"f": -1,
"k": 1,
}},
]);
No comments:
Post a Comment