I have the follow script to change my data within Mongo DB:db.TRACKING_DATA.find( { 'eventdata' : { $type : 2 } } ).forEach( function (x) { x.eventdata = JSON.parse(x.eventdata);     db.TRACKING_DATA.save(x);});db.TRACKING_DATA.find().forEach(    function(doc) {    var QueryDate = doc.eventdata.QueryDate;        if(QueryDate!=null)        db.TRACKING_DATA.update({             _id: doc._id                 }, {                     $set: {                            eventdata.QueryDate: new Date(doc.eventdata.QueryDate)                                }                }        ) });db.TRACKING_DATA.find().forEach(    function(doc) {            var Viewed = doc.eventdata.Viewed;        if (Viewed instanceof Array && Viewed[0])             db.TRACKING_DATA.update({             _id: doc._id ,eventdata.Viewed.viewDate:doc.eventdata.Viewed[0].viewDate             },{                 $set: {                                      eventdata.Viewed.$.viewDate: new Date( doc.eventdata.Viewed[0].viewDate)                                }                }              )         });db.TRACKING_DATA.find().forEach(    function(doc) {        var Viewed = doc.eventdata.Viewed;        if (Viewed instanceof Array && Viewed[0]) {            var Message = Viewed[0].Message;            if (Message instanceof Array && Message[0]) {                db.TRACKING_DATA.update({                    _id : doc._id,                    eventdata.Viewed.viewDate : Viewed[0].viewDate                }, {                    $set : {                        eventdata.Viewed.$.Message.0.MessageDate : new Date(Message[0].MessageDate)                    }                });            }        }    }); db.TRACKING_DATA.find().forEach(         function(doc) {                 var Viewed = doc.eventdata.Viewed;                     if (Viewed instanceof Array && Viewed[0]) {                             var Message = Viewed[0].Message;                                 if (Message instanceof Array && Message[0]) {                                          db.TRACKING_DATA.update({                                                 _id : doc._id,                                                     eventdata.Viewed.viewDate : Viewed[0].viewDate                                                 }, {                                                     $set : {                                                             eventdata.Viewed.$.Message.0.Response.0.ResponseDate : new Date(Message[0].Response[0].ResponseDate)                                                         }                                                 });                                         }                                 }                         });It runs, however, it is taking a very long time ~4hrs to change ~8million documents.  How can I speed up the efficiency of this, to reduce the time it takes to run?Here is the MongoDB structure.{_id: fe50fdee-4ea3-4824-94af-f369633c0c7a,_class: com.tracking.daoservice.model.TrackingData,modified: ISODate(2014-09-10T23:38:48.407Z),eventtype: William-Test,eventdata: {    QueryDate: 01-APR-2014,    SearchQuery: {        keyword: Java,        location: Santa Clara, CA,        Facet: skill~java~perl|workAuth~USC,        SearchAgentId: 4299    },    Viewed: [        {            ViewedID: 8992ade400a,            Dockey: 3323aba3233,            PID: 32399a,            actionsTaken: email|direct message|report seeker,            viewDate: 01-APR-2014,            MessageSent: true,            Message: [                {                    MessageID: 123aca323,                    Delivered: True,                    Opened: True,                    ClickThroughRate: NotBad,                    MessageDate: 02-APR-2014,                    Response: [                        {                            ResponseId: a323a9da,                            ResponseDate: 23-APR-2014                        }                    ]                }            ]        }    ]},eventsource: API-Dev Test - JMachine,sourceip: myIp,entityid: TmoneyBunnyWunny,groupid: Dice,datecreated: ISODate(2014-09-10T23:38:48.405Z)}
Migrating Data in Mongo
javascript;optimization;mongodb