how to format the date returned by mongodb in node.js [ data is in array ] -


i using mongoose , using

objmodel.find(query, function(err,result){         callbackvalue(err,result); }); 

prototype of code.

that result object contains array of json like

{   "feild1":"",   "datefield" :"",   "field":[      {      "datefield":""      "field2":""  } 

this sample of 1 document in result.

i need change date format ist format , again need show same json array in browser.

what best way achieve ?

i put loop , changed in result object. in mongodb 5 hrs 30 mins lagging same field while making console.log(field) in node.js giving correct. want same in json , has send result response json.

to change schema output, use transform option in toobject method :

mymodel.toobject({ transform : function(model, modelobject, options){     _.each(modelobject.field, function(field, index){         modelobject.field[index].datefield = "yourconverteddate field.datefield";     });           }}); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -