title: unexpected identifier - javascript,node and mongodb
body: <p>Running the code below I get an unexpected identifier error when checking if the documents state has changed. I've Googled this to death. tried to find documentation at Mongodb, here, and other misc sources without any luck. Ive spent the whole day on this and feel pretty stupid by now.</p>
  
  <p>All help is sincerely appreciated.</p>
  
  <pre><code>var MongoClient = require('mongodb').MongoClient;
  
  MongoClient.connect('mongodb://localhost:27017/course', function(err, db) {
  if (err) throw err;
  
  var weather = db.collection('weather');
  
  var filter = {};
  var projection ={'State':1, 'Temperature':1, _id:true};
  var options = { 'skip' : 0,
                  'limit' : 20000 ,
                  'sort' : [['State', 1], ['Temperature', -1]] };
  var cursor = weather.find(filter, projection, options);
  var month_high = false;
  var prevState = '';
  var curID = '';
  var operation = {'_id':curID,'$set':{'month_high':true}};
  
  
  // get first document
  cursor.first();
  
  // initialize vars
  prevState = doc.State;
  
  // cycle through documents
  cursor.each(function(err, doc) {
      if(err) throw err;
      if(doc == null) {
          return db.close();
      }
      //Save current document Id
      curID = doc._id;
  
      // Check if State has changgd 
      if prevState != doc.state{
          //If State has changed update the document 
          weather.update(operation,function(err,doc));
          console.dir(doc); //we expect four documents to ouput.
      }
          // save current doc.state as previous state 
          prevState = doc.State;
  
     ;})
  });
  </code></pre>
  
  <p>});</p>