Created
October 27, 2015 10:27
-
-
Save goodbedford/7fcce41baa2efbbab772 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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