node.js - mongoose stringify removes empty elements -
i retreiving mongoose object empty values mongo db :
{ _id: 53049728456d4416243bf65f, usercreated: {}, status: { usercreated: {} }, user: 'patrice', } which fine because there no data.
but when stringify json.stringify(obj) :
{ _id: 53049728456d4416243bf65f, user: 'patrice' } the keys usercreated , status haven't been stringified , don't appear in output...
any idea comes , how arrount ?
my model :
new mongoose.schema({ user: type: string, default: '', status: { name: { type: string, default: '' }, usercreated: { time: { type: date, default: date.now } } }, usercreated: { time: { type: date, default: date.now } } }) p.
json.stringify doesn't strip empty objects, mongoose specific.
i'd recommend trying .toobject() or .tojson()
http://mongoosejs.com/docs/api.html#document_document-toobject
this 1 called during .stringify cutting out empty objects. http://mongoosejs.com/docs/api.html#document_document-tojson
so try first:
json.stringify(obj.toobject());
Comments
Post a Comment