javascript - How to update a field of collection efficient in MongoDB? -


i have dataset

{"id":1,"timestamp":"mon, 11 may 2015 07:57:46 gmt","brand":"a"} {"id":2,"timestamp":"mon, 11 may 2015 08:57:46 gmt","brand":"a"} 

the expected result of data

{"id":1,"timestamp":isodate("2015-05-11t07:57:46z"),"brand":"a"} {"id":2,"timestamp":isodate("2015-05-11t08:57:46z"),"brand":"b"} 

it means want revise timestamp in each row string isodate current code

db.tmpall.find().foreach(     function (a) {         a.timestamp = new date(a.timestamp);         db.tmpall2.insert(a);     } ); 

it runs sucessfully, take couple minutes run code , need create new collection. there efficient way it?

you don't need create new collection. use collection.save method update document.

db.tmpall.find().foreach(function(doc){     doc.timestamp = new date(doc.timestamp);      db.tmpall.save(doc);  }) 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -