Advertisement
zinch

Remove students lowest homework score in Mongo Shell

Aug 24th, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. db.students.find({}, {'_id':1, 'scores': 1}, {'scores.score': 1}).forEach(function(stud) {
  3.    
  4.     var len = stud.scores.length;
  5.     var removeIdx = -1;
  6.     for (var i = 0; i < len; i++) {
  7.         if (stud.scores[i].type === 'homework') {
  8.             removeIdx = i;
  9.         }
  10.     }
  11.    
  12.     stud.scores.splice(removeIdx, 1)
  13.    
  14.     db.students.update({'_id': stud['_id']}, {$set: {'scores':stud.scores}})
  15. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement