How to trigger a function whenever a mongoose document is updated
You need to use the middleware a.k.a. hooks:
Middleware (also called pre and post hooks) are functions which are passed control during execution of asynchronous functions.
See the docs:
- http://mongoosejs.com/docs/middleware.html