Last active
August 29, 2015 14:14
-
-
Save hperantunes/d51111f96919e27d1515 to your computer and use it in GitHub Desktop.
M101P - Homework 3.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.students.find() | |
db.students.find().forEach(function(student) { | |
var lowest = -1; | |
for (var i = 0; i < student.scores.length; i++) { | |
if (student.scores[i].type == 'homework') { | |
lowest = lowest == -1 || student.scores[i].score < student.scores[lowest].score ? i : lowest; | |
} | |
} | |
if (lowest > -1) { | |
student.scores.splice(lowest, 1); | |
db.students.save(student); | |
} | |
}) | |
db.students.count() | |
db.students.find({_id : 137}).pretty() | |
db.students.aggregate( { '$unwind' : '$scores' } , { '$group' : { '_id' : '$_id' , 'average' : { $avg : '$scores.score' } } } , { '$sort' : { 'average' : -1 } } , { '$limit' : 1 } ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment