Skip to content

Instantly share code, notes, and snippets.

@goodbedford
Created October 27, 2015 10:27
Show Gist options
  • Save goodbedford/7fcce41baa2efbbab772 to your computer and use it in GitHub Desktop.
Save goodbedford/7fcce41baa2efbbab772 to your computer and use it in GitHub Desktop.
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017/weather', function(err, db) {
if (err) throw err;
var query = {};
var options = { 'sort' : [ ['State', 1],
['Temperature', -1] ]
};
var cursor = db.collection('weather').find(query, {}, options);
var tempState = '';
var topStates = [];
var states = [];
cursor.each( function (err, doc) {
if (err) throw err;
if (doc == null) {
return db.close();
}
if (doc.State !== tempState){
tempState = doc.State;
doc['month_high'] = true;
db.collection('weather').save(doc);
console.log(doc);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment