Skip to content

Commit ff54943

Browse files
committed
feat(statistics): produce monthly statistics
1 parent b0cf5e8 commit ff54943

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/db.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,25 @@ export function countRequests() {
3131
{
3232
$project: {
3333
affiliations: { $objectToArray: "$user.affiliations" },
34+
month: { $month: { $toDate: "$date" } },
35+
year: { $year: { $toDate: "$date" } },
3436
}
3537
},
3638
{
3739
$unwind: "$affiliations"
3840
},
3941
{
4042
$group: {
41-
_id: "$affiliations.k",
43+
_id: {
44+
month: "$month",
45+
year: "$year",
46+
affiliation: "$affiliations.k"
47+
},
4248
count: { $sum: 1 }
4349
}
4450
},
4551
{
46-
$sort: { count: -1 }
52+
$sort: { "_id.year": 1, "_id.month": 1, count: -1 }
4753
}
4854
])
4955
.toArray();

0 commit comments

Comments
 (0)