javascript - JSON element added not showing -
i using express.js develop api. have json object returned mongoose , need add en element each element in result.docs.
i doing follows:
for(a in result.docs) { result.docs[a].links={ "test":'test', "test": 'test', "test": 'test' }; }
after doing returning result object, links not added. on other hand if write
console.log(result.docs[1].links);
the object shown properly.
any ideas please?
thanks
possibly you're working mongoose document instance instead of plain object, in case use toobject
method plain object, implementation be:
var objs = []; for(var in result.docs) { var obj = result.docs[a].toobject(); obj.links = { "test":'test', "test": 'test', "test": 'test' }; objs.push(obj); } // objs
Comments
Post a Comment