Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. { "_id" : ObjectId("5340eff554f98e32c5990b4f"), "Day" : 8, "Time" : 1553, "State" : "Florida", "Airport" : "ORL", "Temperature" : 82, "Humidity" : 55, "Wind Speed" : 5, "Wind Direction" : 170, "Station Pressure" : 29.97, "Sea Level Pressure" : 196 }
  2. { "_id" : ObjectId("5340eff554f98e32c5990b5f"), "Day" : 9, "Time" : 1253, "State" : "Florida", "Airport" : "ORL", "Temperature" : 82, "Humidity" : 60, "Wind Speed" : 13, "Wind Direction" : 190, "Station Pressure" : 29.91, "Sea Level Pressure" : 175 }
  3. { "_id" : ObjectId("5340eff554f98e32c5990b60"), "Day" : 9, "Time" : 1353, "State" : "Florida", "Airport" : "ORL", "Temperature" : 82, "Humidity" : 58, "Wind Speed" : 11, "Wind Direction" : 190, "Station Pressure" : 29.88, "Sea Level Pressure" : 166 }
  4. { "_id" : ObjectId("5340eff554f98e32c5990b4c"), "Day" : 8, "Time" : 1253, "State" : "Florida", "Airport" : "ORL", "Temperature" : 81, "Humidity" : 54, "Wind Speed" : 4, "Wind Direction" : 180, "Station Pressure" : 30.02, "Sea Level Pressure" : 214 }
  5.  
  6. var updateQuery = {'_id':doc['_id']};
  7. var operator = {$set:{'month_high' : true}};
  8. db.collection('temps').update(updateQuery,operator,callback)
  9.  
  10. { "Airport" : "ORL", "Day" : 8, "Humidity" : 55, "Sea Level Pressure" : 196, "State" : "Florida", "Station Pressure" : 29.97, "Temperature" : 82, "Time" : 1553, "Wind Direction" : 170, "Wind Speed" : 5, "_id" : ObjectId("5340eff554f98e32c5990b4f"), "month_high" : true }
  11. { "_id" : ObjectId("5340eff554f98e32c5990b5f"), "Day" : 9, "Time" : 1253, "State" : "Florida", "Airport" : "ORL", "Temperature" : 82, "Humidity" : 60, "Wind Speed" : 13, "Wind Direction" : 190, "Station Pressure" : 29.91, "Sea Level Pressure" : 175 }
  12. { "_id" : ObjectId("5340eff554f98e32c5990b60"), "Day" : 9, "Time" : 1353, "State" : "Florida", "Airport" : "ORL", "Temperature" : 82, "Humidity" : 58, "Wind Speed" : 11, "Wind Direction" : 190, "Station Pressure" : 29.88, "Sea Level Pressure" : 166 }
  13. { "_id" : ObjectId("5340eff554f98e32c5990b4c"), "Day" : 8, "Time" : 1253, "State" : "Florida", "Airport" : "ORL", "Temperature" : 81, "Humidity" : 54, "Wind Speed" : 4, "Wind Direction" : 180, "Station Pressure" : 30.02, "Sea Level Pressure" : 214 }
  14.  
  15. db.collection.find({},{
  16. "Airport":1,
  17. "Day":1,
  18. "Humidity":1,
  19. "Sea Level Pressure":1,
  20. "State":1,
  21. "Station Pressure":1,
  22. "Temperature":1,
  23. "Time":1,
  24. "Wind Direction":1,
  25. "Wind Speed":1,
  26. "_id":1,
  27. "month_high":1
  28. });
  29.  
  30. {
  31. "Airport":"ORL",
  32. "Day":8,
  33. "Humidity":55,
  34. "Sea Level Pressure":196,
  35. "State":"Florida",
  36. "Station Pressure":29.97,
  37. "Temperature":82,
  38. "Time":1553,
  39. "Wind Direction":170,
  40. "Wind Speed":5,
  41. "_id":ObjectId("5340eff554f98e32c5990b4f"),
  42. "month_high":true
  43. }, ...
  44.  
  45. var json = {"name": "David", "age" : 78, "NoOfVisits" : 4 };
  46. console.log(json);
  47. //outputs - Object {name: "David", age: 78, NoOfVisits: 4}
  48. //change order to NoOfVisits,age,name
  49.  
  50. var k = JSON.parse(JSON.stringify( json, ["NoOfVisits","age","name"] , 4));
  51. console.log(k);
  52. //outputs - Object {NoOfVisits: 4, age: 78, name: "David"}
  53.  
  54. db.collection('data').aggregate([{$group:{"_id":"$State"}}],function(err,results){
  55. for(var i=0;i<results.length;i++){
  56.  
  57. var query = {'State':results[i]._id};
  58. var cursor = db.collection('data').find(query);
  59. cursor.limit(1);
  60. cursor.sort('Temperature',-1);
  61.  
  62. cursor.each(function(err, doc) {
  63. if(err) throw err;
  64. if(doc == null) {
  65. return;
  66. }
  67.  
  68. // I just had to change the following query and it worked for me
  69. // rest of the code remains same.
  70. var updateQuery = {};
  71. updateQuery['_id'] = doc['_id'];
  72. doc['month_high'] = true;
  73.  
  74. db.collection('data').update(updateQuery,doc, function(err, updated) {
  75. if(err) throw err;
  76.  
  77. console.dir("Successfully updated " + updated + " document!");
  78.  
  79. return;
  80. });
  81. //console.dir(doc._id);
  82. });
  83. }
  84. });
  85.  
  86. var updateQuery = {'_id':doc['_id']};
  87. var operator = {$set:{'month_high' : true}};
  88. db.collection('data').update(updateQuery,operator,callback)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement