File tree Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Expand file tree Collapse file tree 1 file changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -48,8 +48,46 @@ export function countRequests() {
48
48
count : { $sum : 1 }
49
49
}
50
50
} ,
51
+ // Umwandlung der _id-Struktur zum Vereinfachen der nächsten Gruppierung
51
52
{
52
- $sort : { "_id.year" : 1 , "_id.month" : 1 , count : - 1 }
53
+ $project : {
54
+ year : "$_id.year" ,
55
+ month : "$_id.month" ,
56
+ affiliation : "$_id.affiliation" ,
57
+ count : 1 ,
58
+ _id : 0
59
+ }
60
+ } ,
61
+ // Zweite Gruppierungsstufe nach Jahr und Monat, wobei die Ergebnisse je Affiliation gesammelt werden
62
+ {
63
+ $group : {
64
+ _id : {
65
+ year : "$year" ,
66
+ month : "$month"
67
+ } ,
68
+ affiliations : {
69
+ $push : {
70
+ affiliation : "$affiliation" ,
71
+ count : "$count"
72
+ }
73
+ }
74
+ }
75
+ } ,
76
+ // Finalisierung der Struktur: Gruppierung nach Jahr und Anordnung der Monate je Jahr
77
+ {
78
+ $group : {
79
+ _id : "$_id.year" ,
80
+ months : {
81
+ $push : {
82
+ month : "$_id.month" ,
83
+ affiliations : "$affiliations"
84
+ }
85
+ }
86
+ }
87
+ } ,
88
+ // Sortieren der Ergebnisse, zunächst nach Jahr dann innerhalb der Jahre nach Monaten
89
+ {
90
+ $sort : { "_id" : 1 , "months.month" : 1 }
53
91
}
54
92
] )
55
93
. toArray ( ) ;
You can’t perform that action at this time.
0 commit comments