Mongoose asynchronous defaults

javascript, mongoose, node.js

Solution

Yes, in middleware, `this` refers, at runtime, to the model instance.

Problem

It's not in the documentation, but I'm trying to figure out how to set asynchronous defaults with Mongoose. I see the `model.pre("save", function(next){})` setup, but I have no idea how to mutate fields on the model which is currently being saved. Does Mongoose bind this to the item being saved?

Original source