Is there a way to save a model and populate the Dbref-like field within the saved model.
I’m currently doing
dbrefobj.findbyid(id).run(
function (err, dbrefobj) {
topobj.save....
I would like to do something like
topobj.save.populate(dbrefobj)
Thanks!
You can define
'save'middleware in your schema to insert your own processing into the act of saving a document. In your case you’d look up the referenced document and pull in whatever you need from that into the document being saved. See the Mongoose middleware docs here.