node.js - Sort the list and insert a new column in mongodb -


i need sort states , figure out highest temperature each state in weather data residing in mongodb.

how iterate through each record in javascript , insert new column 'month_highest' when figure out highest temperature state ?


day time    state   airport temperature humidity windspeed 1   54  vermont btv 39  57  6 1   154 vermont btv 39  57  4 1   254 vermont btv 39  57  5 1   354 vermont btv 38  70  5 1   454 vermont btv 34  92  11 

16 53 florida orl 46 71 9 16 153 florida orl 47 71 8 16 253 florida orl 46 73 8 16 353 florida orl 47 74 8 16 453 florida orl 46 79 7 16 553 florida orl 46 79 5 16 653 florida orl 46 83 4

mongodb map-reduce

db.temps.mapreduce(     /* map */     function() {         emit( this.state, this.temperature);     },      /* reduce */     function key(key, values) {         var ret = 0;         (var i=0; i<values.length, i++) {             if (values[i] > ret) ret = values[i];         }         return ret     },      /* params */     {          query: {               datetime: {                   $gte: new date('2013-01-01')                  ,$lt: new date('2013-02-01')               }          }           ,sort: {              state:1          }     } ); 

as inserting new month-max, depends on how want store it? how querying data?

you could output results new collection, or use programmatically update collection. depends on how want data shaped. looks flat data stands.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -