I am using mongoose and by 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 is the sample of one document in the result.
i need to change the date format to IST format and again need to show the same json array in the browser.
what is the best way to achieve it ?
I put a loop and changed everything in the result object. in mongodb actually 5 hrs 30 mins is lagging but the same field while making console.log(field) in node.js it is giving correct. But i want the same in the json and it has to be send as result to the response as json.
To change you schema output, use the transform Option in the toObject method like this :
mymodel.toObject({ transform : function(model, modelObject, options){
_.each(modelObject.field, function(field, index){
modelObject.field[index].datefield = "yourconverteddate field.datefield";
});
}});