I have a document from a mongoose find that I want to extend before JSON encoding and sending out as a response. If I try adding properties to the doc it is ignored. The properties don’t appear in Object.getOwnPropertyNames(doc) making a normal extend not possible. The strange thing is that JSON.parse(JSON.encode(doc)) works and returns an object with all of the correct properties. Is there a better way to do this?
I have a document from a mongoose find that I want to extend before
Share
Mongoose
Models inherit fromDocuments, which have atoObject()method. I believe what you’re looking for should be the result ofdoc.toObject().http://mongoosejs.com/docs/api.html#document_Document-toObject