We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8892a71 commit 2b200f9Copy full SHA for 2b200f9
hw5.3/README.md
@@ -65,9 +65,53 @@ mongoimport -d test -c grades --drop grades.json
65
### Response
66
67
````
68
-
+db.grades.aggregate([
69
+ {
70
+ $unwind: '$scores'
71
+ },
72
73
+ $match: {
74
+ 'scores.type': { $in: ['exam', 'homework'] }
75
+ }
76
77
78
+ $group: {
79
+ _id: {
80
+ class_id: '$class_id',
81
+ student_id: '$student_id'
82
83
+ scoresAvg: { $avg: '$scores.score' }
84
85
86
87
+ $project: {
88
+ _id: 0,
89
+ student_id: '$_id.student_id',
90
+ class_id: '$_id.class_id',
91
+ scoresAvg: 1
92
93
94
95
96
97
+ class_id: '$class_id'
98
99
+ avg: {
100
+ $avg: '$scoresAvg'
101
102
103
104
105
+ $sort: {
106
+ 'avg': -1
107
108
109
110
+ $limit: 1
111
112
+])
113
114
-*
115
+* 1
116
117
0 commit comments