How do you turn a Mongoose document into a plain object?
Mongoose Model
s inherit from Document
s, which have a toObject()
method. I believe what you're looking for should be the result of doc.toObject()
.
http://mongoosejs.com/docs/api.html#document_Document-toObject
Another way to do this is to tell Mongoose that all you need is a plain JavaScript version of the returned doc by using lean()
in the query chain. That way Mongoose skips the step of creating the full model instance and you directly get a doc
you can modify:
MyModel.findOne().lean().exec(function(err, doc) { doc.addedProperty = 'foobar'; res.json(doc);});