-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMatchCStudents.js
43 lines (39 loc) · 894 Bytes
/
MatchCStudents.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
db = db.getSiblingDB("sample");
var p1 = db.runCommand(
{ "aggregate" : "scores",
"pipeline" : [
{
$match : {
$and : [
{ "score" : { $gte : 70 } },
{ "score" : { $lte : 79 } }
]
}
} , {
$group : {
_id : "$score",
student : { $addToSet : "$student" }
}
} , {
$unwind : "$student"
} , {
$group : {
_id : "$student",
C_score_count : { $sum : 1 }
}
} , {
$match : { C_score_count : { $gte : 2 } }
} , {
$group : {
_id : "$C_score_count",
students : { $addToSet : "$_id" }
}
} , {
$project : {
"_id" : 0,
"Number_of_C_scores" : "$_id",
"student_ids" : "$students"
}
}
]});
printjson(p1);