title: how to $set a mongoDB cursor in node.js?
body: <p>I have a mongoDB collection which I want to add a field at random locations using <code>$set</code>, at least I am pretty sure its a <code>$set</code>.  Correct me if I am wrong.
  I am including code. Around the middle I include remarks of what I am trying to do:</p>
  
  <pre><code>var MongoClient = require('mongodb').MongoClient;
  
  MongoClient.connect('mongodb://localhost:27017/weather', function(err, db) {
  
      // Also, what is the best way to handle err in this code?
      //if(err) throw err;
  
      var query = { };
      var sortorder = {"State":1, "Temperature":-1}
  
      var xx = null;
  
      //var cursor = db.collection('data').find();
      var cursor = db.collection('data').find().sort(sortorder);
  
      cursor.each(function(err, doc) {
          //if(err) throw err;
  
          if(doc == null) {
              return db.close();
          }
  
  
          if (xx == doc.State){
  
  
          }else{
  
                  console.dir("New state -----------" + doc.State);
                  console.dir("Tempurature -----------" + doc.Temperature);
  
                  // !!!!!!!!!!!!!!!!!!!!!!!!!!   this is the problem area.
                  //--- this is the part I am trying to figure out...
                  update_routine = $set:{"month_high---test001":true};
                  doc.update =  update_routine;
                  //  How do I do a $set operation on a mongoDB cursor.  which I have here.
                  xx = doc.State;
                  // add the field
                  //doc.update();
  
          }
  
          if(doc == null) {
              return db.close();
          }
  
      //app.error(function(err, req, res, next){
      //  console.error(err);
      //  res.send('Fail Whale, yo.');
      //});
  
          //console.dir(doc.State + " is a state!");
      });
  });
  </code></pre>
  
  <p>~~</p>