Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- { "_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 }
- { "_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 }
- { "_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 }
- { "_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 }
- var updateQuery = {'_id':doc['_id']};
- var operator = {$set:{'month_high' : true}};
- db.collection('temps').update(updateQuery,operator,callback)
- { "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 }
- { "_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 }
- { "_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 }
- { "_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 }
- db.collection.find({},{
- "Airport":1,
- "Day":1,
- "Humidity":1,
- "Sea Level Pressure":1,
- "State":1,
- "Station Pressure":1,
- "Temperature":1,
- "Time":1,
- "Wind Direction":1,
- "Wind Speed":1,
- "_id":1,
- "month_high":1
- });
- {
- "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
- }, ...
- var json = {"name": "David", "age" : 78, "NoOfVisits" : 4 };
- console.log(json);
- //outputs - Object {name: "David", age: 78, NoOfVisits: 4}
- //change order to NoOfVisits,age,name
- var k = JSON.parse(JSON.stringify( json, ["NoOfVisits","age","name"] , 4));
- console.log(k);
- //outputs - Object {NoOfVisits: 4, age: 78, name: "David"}
- db.collection('data').aggregate([{$group:{"_id":"$State"}}],function(err,results){
- for(var i=0;i<results.length;i++){
- var query = {'State':results[i]._id};
- var cursor = db.collection('data').find(query);
- cursor.limit(1);
- cursor.sort('Temperature',-1);
- cursor.each(function(err, doc) {
- if(err) throw err;
- if(doc == null) {
- return;
- }
- // I just had to change the following query and it worked for me
- // rest of the code remains same.
- var updateQuery = {};
- updateQuery['_id'] = doc['_id'];
- doc['month_high'] = true;
- db.collection('data').update(updateQuery,doc, function(err, updated) {
- if(err) throw err;
- console.dir("Successfully updated " + updated + " document!");
- return;
- });
- //console.dir(doc._id);
- });
- }
- });
- var updateQuery = {'_id':doc['_id']};
- var operator = {$set:{'month_high' : true}};
- db.collection('data').update(updateQuery,operator,callback)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement