Mongoose Middleware - adriana-401-advanced-javascript/seattle-javascript-401n13 GitHub Wiki
Mongoose is a library used for Mongo to be able to run asynchronous functions.
Query middleware is supported for the following Model and Query functions. In query middleware functions,this
refers to the query.
- count
- deleteMany
- deleteOne
- find
- findOne
- findOneAndDelete
- findOneAndRemove
- findOneAndUpdate
- remove
- update
- updateOne
- updateMany
Pre
Pre middleware functions are executed one after another, when each middleware calls next.
let schema = new Schema(..);
schema.pre('save', function(next) {
// here is where we have it do the stuff we need
next();
});
https://mongoosejs.com/docs/middleware.html