Advertisement
michaelpastes

Untitled

Sep 3rd, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. var MongoClient = require('mongodb').MongoClient;
  2.  
  3. MongoClient.connect('mongodb://localhost:27017/school', function(err, db) {
  4. if(err) throw err;
  5.  
  6. var cursor = db.collection('students').find();
  7.  
  8.  
  9. cursor.each(function(err, doc) {
  10. if(err) throw err;
  11.  
  12. console.log(doc);
  13.  
  14. var twoscore = doc.scores[2]['score']
  15. var threescore = doc.scores[3]['score']
  16.  
  17. if ( twoscore > threescore){
  18. doc.scores.splice(3,1);
  19.  
  20. console.log('2 is bigger than 3');
  21. }else {
  22.  
  23. doc.scores.splice(2,1);
  24. console.log('3 is bigger than 2');
  25.  
  26. }
  27.  
  28.  
  29. db.collection('students').save(doc, function(err, saved) {
  30. if(err) throw err;
  31.  
  32. console.dir(saved);
  33. console.log('is this what you expected?');
  34.  
  35. return db.close();
  36. });
  37.  
  38.  
  39. });
  40. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement