var studs db students find for var studs length -1 i-- db students upd

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
var studs = db.students.find();
for (var i = studs.length()-1; i >= 0; i--) {
db.students.update(
{ _id: i },
{
$pull: {
"scores": getMinScore(studs[i])
}
}
);
}
function getMinScore(stud) {
var i, minScore = stud.scores[0].score;
for (i = 1; i < stud.scores.length; i++) {
if (stud.scores[i].score < minScore) {
minScore = stud.scores[i];
}
}
return minScore;
}