Skip to content

Commit 1baf2a1

Browse files
committed
feat: add affiliations in usage stats
- update aggregation in /dashboard route to include affiliations
1 parent 96b842d commit 1baf2a1

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/db.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ export function logRequest(request) {
2828
export function countRequests() {
2929
return db?.collection('requests')
3030
.aggregate([
31-
{
32-
$group: {
33-
_id: "$user.email",
34-
count: { $count: {} }
35-
}
36-
}
37-
])
31+
{ $project: { user: 1, affiliations: "$user.affiliations" } },
32+
{ $group: { _id: "$user.email", affiliations: { $mergeObjects: "$affiliations" }, count: { $count: {} } } },
33+
{ $sort: { count: -1 } }])
3834
.toArray();
39-
}
35+
}

0 commit comments

Comments
 (0)