mongoose Mongoose Middleware

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


In mongoose, Middlewares are also called as pre and post hooks.

There are two types of middleware

Both of these middleware support pre and post hooks.

  1. Document middleware

    Its supported for document functions init, validate, save and remove

  1. Query middleware

    Its supported for query functions count, find, findOne, findOneAndRemove, findOneAndUpdate, insertMany and update.

Pre and Post hooks

There are two types of Pre hooks

  1. serial

    As the name suggests, Its executed in serial order i..e one after another

  1. parallel

    Parallel middleware offers more fine-grained flow control and the hooked method is not executed until done is called by all parallel middleware.

Post Middleware are executed after the hooked method and all of its pre middleware have been completed.

hooked methods are the functions supported by document middleware. init, validate, save, remove

Got any mongoose Question?