Maybe a bit astray to the answer, but if anyone who is looking to do the other way around, you can use Model.hydrate()
(since mongoose v4) to convert a javascript object (JSON) to a mongoose document.
An useful case would be when you using Model.aggregate(...)
. Because it is actually returning plain JS object, so you may want to convert it into a mongoose document in order to get access to Model.method
(e.g. your virtual property defined in the schema).
PS. I thought it should have a thread running like "Convert json to Mongoose docs", but actually not, and since I've found out the answer, so I think it is not good to do self-post-and-self-answer.