Skip to content

Commit 2b200f9

Browse files
committed
Homework 5.3
1 parent 8892a71 commit 2b200f9

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

hw5.3/README.md

+46-2
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,53 @@ mongoimport -d test -c grades --drop grades.json
6565
### Response
6666

6767
````
68-
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+
$group: {
96+
_id: {
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+
])
69113
````
70114

71-
*
115+
* 1
72116

73117

0 commit comments

Comments
 (0)