I am looking for a good way to save an Account to MongoDB using mongoose.

My problem is: The password is hashed asynchronously. A setter wont work here because it only works synchronous.

I thought about 2 ways:

  • Create an instance of the model and save it in the callback of the hash function.

  • Creating a pre hook on 'save'

Is there any good solution on this problem?

Edit
Report