Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var MongoClient = require('mongodb').MongoClient;
- MongoClient.connect('mongodb://localhost:27017/school', function(err, db) {
- if(err) throw err;
- var cursor = db.collection('students').find();
- cursor.each(function(err, doc) {
- if(err) throw err;
- console.log(doc);
- var twoscore = doc.scores[2]['score']
- var threescore = doc.scores[3]['score']
- if ( twoscore > threescore){
- doc.scores.splice(3,1);
- console.log('2 is bigger than 3');
- }else {
- doc.scores.splice(2,1);
- console.log('3 is bigger than 2');
- }
- db.collection('students').save(doc, function(err, saved) {
- if(err) throw err;
- console.dir(saved);
- console.log('is this what you expected?');
- return db.close();
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement