CSC 369: Distributed Computing Alex Dekhtyar April 17 Day 6: The - - PowerPoint PPT Presentation

csc 369 distributed computing
SMART_READER_LITE
LIVE PREVIEW

CSC 369: Distributed Computing Alex Dekhtyar April 17 Day 6: The - - PowerPoint PPT Presentation

CSC 369: Distributed Computing Alex Dekhtyar April 17 Day 6: The Algebra Of Data Transformations Part II db.collection.aggregate() Housekeeping Lab 2: Submit from unix1-2-3-4-5 handin dekhtyar lab02 <files> Lab 3:


slide-1
SLIDE 1

CSC 369: Distributed Computing

Alex Dekhtyar

Day 6: The Algebra Of Data Transformations Part II db.collection.aggregate()

April 17

slide-2
SLIDE 2
slide-3
SLIDE 3

Housekeeping

  • Lab 2:

○ Submit from unix1-2-3-4-5 ○ handin dekhtyar lab02 <files>

  • Lab 3:
  • Lab 4: Python application, teams of 2.
slide-4
SLIDE 4

Recall from last class

{name:”Alex”, teaches:[“CSC 369”, “DATA 452”], department:”CSSE”, enrollments:[28,20], position: “professor”,

  • ffice:{building:14, room:210}

}

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

Decomposition into atomic operations in “Generalized” Data Algebra

slide-5
SLIDE 5

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

slide-6
SLIDE 6

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

slide-7
SLIDE 7

Express using these operations….

Relational Algebra

Selection Projection Set Operations Join Sort Grouping/Aggregation

Generalized Algebra

Filtering Projection/Transformation Join Grouping/Aggregation Sort

slide-8
SLIDE 8

Very Tersely

Filtering Projection Transformation Join Grouping Sort

Given a condition - keep only objects that satisfy it Modify the contents of its object based solely on what’s in the object itself

Aggregation

Break collection into groups, each representing

  • bjects with same values of some keys

Combine objects from two different collections based on matches in values of some keys Compute an aggregate value over a set of objects Return objects in a specific order

slide-9
SLIDE 9

… and a few more

Ungrouping Unwinding Limit Skip

Opposite of grouping - build an object for each element of an array Return a specific number of documents

Sample

Return documents after skipping a specified number Return a random sample of documents

slide-10
SLIDE 10

Let’s use our intuition

slide-11
SLIDE 11

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

Exercise Time!!

File posted to Slack/chat.

slide-12
SLIDE 12

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

Filtering Projection Aggregation Projection Aggregation Projection Filtering

slide-13
SLIDE 13

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

Exercise Time!!

slide-14
SLIDE 14

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

Unwinding Filtering Projection Grouping Sort

slide-15
SLIDE 15

Now, let’s learn all this for real...

db.collection.aggregate(<aggregation pipeline>)

slide-16
SLIDE 16

Now, let’s learn all this for real...

db.collection.aggregate({$operation:{<doc>}}, {$operation:{<doc>}}, …, })

slide-17
SLIDE 17

Now, let’s learn all this for real...

db.collection.aggregate({$operation:{<doc>}}, {$operation:{<doc>}}, …, }) In Lecture: basic ideas In Lab: all the syntax you can handle

slide-18
SLIDE 18

$operation

Filtering Projection Join Grouping Sort Aggregation $match $project $set $unset $addFields $redact $replaceRoot $group $bucket $bucketAuto $lookup $graphLookup $sortByCount $sort

slide-19
SLIDE 19

$operation

Filtering Projection Join Grouping Sort Aggregation $match $project $group $lookup $sort

slide-20
SLIDE 20

$operation

Filtering Projection Join Grouping Sort Aggregation $match $project $group $lookup $sort Unwinding Limit Skip Sample $unwind $limit $skip $sample

slide-21
SLIDE 21

Let’s Learn By Doing

Query 2 first (it is simpler) Query 1 second (it has layers)

slide-22
SLIDE 22

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

Unwinding Filtering Projection Grouping Sort

slide-23
SLIDE 23

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

$match $project $group $sort $unwind

slide-24
SLIDE 24

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

$match $project $group $sort $unwind

slide-25
SLIDE 25

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

$match $project $group $sort $unwind {$unwind: “$teaches”}

slide-26
SLIDE 26

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

$match $project $group $sort $unwind {$unwind: “$teaches”} {$match: {teaches: {$in: [“CSC”, “CPE”,”DATA”]} }}

slide-27
SLIDE 27

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

$match $project $group $sort $unwind {$unwind: “$teaches”} {$match: {teaches: {$in: [/^CSC/, /^CPE/,/^DATA/]} }}

Regular Expressions!!!

slide-28
SLIDE 28

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

$match $project $group $sort $unwind {$unwind: “$teaches”} {$match: {teaches: {$in: [/^CSC/, /^CPE/,/^DATA/]}}}

{"name" : "Alex", "teaches" : "CSC 369", "department" : "CSSE", "enrollments" : [28,20], "position" : "professor", "office" : {"building" : 14, "room" : 210 } }

slide-29
SLIDE 29

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

$match $project $group $sort $unwind {$unwind: “$teaches”} {$match: {teaches: {$in: [/^CSC/, /^CPE/,/^DATA/]}}}

{"name" : "Alex", "teaches" : "CSC 369", "department" : "CSSE", "enrollments" : [28,20], "position" : "professor", "office" : {"building" : 14, "room" : 210 } }

{$project:{_id:0, Name:1, department:1, course:”$teaches”} }

slide-30
SLIDE 30

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

$match $project $group $sort $unwind {$unwind: “$teaches”} {$match: {teaches: {$in: [/^CSC/, /^CPE/,/^DATA/]}}} {$project:{_id:0, Name:1, department:1, course:”$teaches”}} {$group:{_id:”$course”, instructors:{$push: { name:”$name”, department:”$department”}} } }

slide-31
SLIDE 31

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

$match $project $group $sort $unwind {$unwind: “$teaches”} {$match: {teaches: {$in: [/^CSC/, /^CPE/,/^DATA/]}}} {$project:{_id:0, Name:1, department:1, course:”$teaches”}} {$group:{_id:”$course”, instructors:{$push: { name:”$name”, department:”$department”}} } {$project:{_id:0, instructors:1, $course:”$_id”}}

slide-32
SLIDE 32

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

$match $project $group $sort $unwind

{$unwind: “$teaches”} {$match: {teaches: {$in: [/^CSC/, /^CPE/,/^DATA/]}}} {$project:{_id:0, Name:1, department:1, course:”$teaches”}} {$group:{_id:”$course”, instructors:{$push: { name:”$name”, department:”$department”}} } {$project:{_id:0, instructors:1, $course:”$_id”}}

slide-33
SLIDE 33

Keep information about only “CSC”, “CPE”, and “DATA” courses. Deconstruct “teaches” arrays, create one

  • bject per instructor-course pairing

Remove unnecessary data For each course, combine instructors teaching it into a list Sort?

Q2: Report a list of instructors for each “CSC”, “CPE” and “DATA” course. For each instructor, list name and department.

$match $project $group $sort $unwind

{$unwind: “$teaches”} {$match: {teaches: {$in: [/^CSC/, /^CPE/,/^DATA/]}}} {$project:{_id:0, Name:1, department:1, course:”$teaches”}} {$group:{_id:”$course”, instructors:{$push: { name:”$name”, department:”$department”}} } {$project:{_id:0, instructors:1, $course:”$_id”}}

{$sort: {course:1}}

slide-34
SLIDE 34

db.spring.aggregate( {$unwind:"$teaches"}, {$match: {teaches: {$in:[/^CSC/, /^CPE/, /^DATA/]} }}, {$project: {_id:0, name:1, department:1, course:"$teaches"} }, {$group:{_id:"$course", instructors:{$push: {name:"$name", department:"$department"} }} }, {$project:{_id:0, instructors:1, course:"$_id"}}, {$sort:{course:1}} )

slide-35
SLIDE 35

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

Filtering Projection Aggregation Projection Aggregation Projection Filtering

slide-36
SLIDE 36

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match

slide-37
SLIDE 37

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match {$match: {department:"CSSE"}} Same as for db.collection.find()

slide-38
SLIDE 38

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match {$match: {department:"CSSE"}} {$project:{... } }

{name:”Alex”, teaches:[“CSC 369”, “DATA 452”], department:”CSSE”, enrollments:[28,20], position: “professor”,

  • ffice:{building:14, room:210}

}

slide-39
SLIDE 39

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match {$match: {department:"CSSE"}} {$project:{_id:0, name:1, enrollments:1 } }

slide-40
SLIDE 40

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match {$match: {department:"CSSE"}} {$project:{_id:0, name:1, enrollments:1 } }

{ "name" : "Alex", "enrollments" : [ 28, 20 ] }

{$project:{name:1, enrollments:{$sum:”$enrollments”} } }

28+20

slide-41
SLIDE 41

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match {$match: {department:"CSSE"}} {$project:{_id:0, name:1, enrollments:1 } } {$project:{name:1, enrollments:{$sum:”$enrollments”} } }

{ "name" : "Kirsten", "enrollments" : 108 } { "name" : "Alex", "enrollments" : 48 }

slide-42
SLIDE 42

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match {$match: {department:"CSSE"}} {$project:{_id:0, name:1, enrollments:1 } } {$project:{name:1, enrollments:{$sum:”$enrollments”} } }

{ "name" : "Kirsten", "enrollments" : 108 } { "name" : "Alex", "enrollments" : 48 }

{$group:{_id:”1” mEnr: {$max: “$enrollments”}} }

slide-43
SLIDE 43

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match {$match: {department:"CSSE"}} {$project:{_id:0, name:1, enrollments:1 } } {$project:{name:1, enrollments:{$sum:”$enrollments”} } }

{ "name" : "Kirsten", "enrollments" : 108 } { "name" : "Alex", "enrollments" : 48 }

{$group:{_id:”1” data:{$push:{name:”$name”, enr:”$enrollments”}}, mEnr: {$max: “$enrollments”}} }

slide-44
SLIDE 44

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match {$match: {department:"CSSE"}} {$project:{_id:0, name:1, enrollments:1 } } {$project:{name:1, enrollments:{$sum:”$enrollments”} } }

{ "name" : "Kirsten", "enrollments" : 108 } { "name" : "Alex", "enrollments" : 48 }

{$group:{_id:”1” data:{$push:{name:”$name”, enr:”$enrollments”}}, mEnr: {$max: “$enrollments”}} }, {$unwind:”$data”}

slide-45
SLIDE 45

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match

{$match: {department:"CSSE"}} {$project:{_id:0, name:1, enrollments:1 } } {$project:{name:1, enrollments:{$sum:”$enrollments”} }} {$group:{_id:”1” data:{$push:{name:”$name”, enr:”$enrollments”}}, mEnr: {$max: “$enrollments”}} }, {$unwind:”$data”}

{$match:{ maxEnrollment:”$data.enrollments” }}

slide-46
SLIDE 46

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match

{$match: {department:"CSSE"}} {$project:{_id:0, name:1, enrollments:1 } } {$project:{name:1, enrollments:{$sum:”$enrollments”} }} {$group:{_id:”1” data:{$push:{name:”$name”, enr:”$enrollments”}}, mEnr: {$max: “$enrollments”}} }, {$unwind:”$data”}

{$match:{ maxEnrollment:”$data.enrollments” }}

slide-47
SLIDE 47

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match

{$match: {department:"CSSE"}} {$project:{_id:0, name:1, enrollments:1 } } {$project:{name:1, enrollments:{$sum:”$enrollments”} }} {$group:{_id:”1” data:{$push:{name:”$name”, enr:”$enrollments”}}, mEnr: {$max: “$enrollments”}} }, {$unwind:”$data”}

{$project:{diff: {$subtract:[“$maxEnrollment”, “$data.enrollments”]} } {$match:{ maxEnrollment:”$data.enrollments” }}

slide-48
SLIDE 48

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match

{$match: {department:"CSSE"}} {$project:{_id:0, name:1, enrollments:1 } } {$project:{name:1, enrollments:{$sum:”$enrollments”} }} {$group:{_id:”1” data:{$push:{name:”$name”, enr:”$enrollments”}}, mEnr: {$max: “$enrollments”}} }, {$unwind:”$data”}

{$project:{diff: {$subtract:[“$maxEnrollment”, “$data.enrollments”]}, _id:0, name:”$data.name”, enrollments:”$data.enrollments” } {$match:{ maxEnrollment:”$data.enrollments” }}

slide-49
SLIDE 49

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match

{$match: {department:"CSSE"}} {$project:{_id:0, name:1, enrollments:1 } } {$project:{name:1, enrollments:{$sum:”$enrollments”} }} {$group:{_id:”1” data:{$push:{name:”$name”, enr:”$enrollments”}}, mEnr: {$max: “$enrollments”}} }, {$unwind:”$data”}

{$project:{diff: {$subtract:[“$maxEnrollment”, “$data.enrollments”]}, _id:0, name:”$data.name”, enrollments:”$data.enrollments” } {$match:{ diff:0} }

slide-50
SLIDE 50

Find the largest total enrollment for a CSSE instructor Find the total enrollment for each CSSE instructor and number of sections taught Compare each instructor’s total enrollment to the largest; keep only instructors with largest enrollment Keep only CSSE instructors Remove unnecessary data

Q1: Find all CSSE faculty with highest total enrollments, report name, number of sections taught, total enrollment

$match

$project

$group

$project

$match

{$match: {department:"CSSE"}} {$project:{_id:0, name:1, enrollments:1 } } {$project:{name:1, enrollments:{$sum:”$enrollments”} }} {$group:{_id:”1” data:{$push:{name:”$name”, enr:”$enrollments”}}, mEnr: {$max: “$enrollments”}} }, {$unwind:”$data”}

{$project:{diff: {$subtract:[“$maxEnrollment”, “$data.enrollments”]}, _id:0, name:”$data.name”, enrollments:”$data.enrollments” } {$match:{ diff:0} } {$project: {diff:0}}

slide-51
SLIDE 51

db.spring.aggregate( {$match: {department:"CSSE"}}, {$project:{_id:0, name:1, enrollments:1} //cleaning }, {$project:{name:1, //transformation enrollments: {$sum: "$enrollments"}} }, {$group:{ _id:"1", maxEnrollment:{$max:"$enrollments"}, data: {$push:{name:"$name", enrollments:"$enrollments"}} } }, {$unwind:"$data"}, {$project:{_id:0, diff: {$subtract:["$maxEnrollment", "$data.enrollments"]}, name:"$data.name", enrollments:"$data.enrollments" } }, {$match:{diff:0}}, {$project:{diff:0}} )