Schemas are pluggable, that is, they allow for applying pre-packaged capabilities to extend their functionality. This is a very powerful feature.

    Plugins are a tool for reusing logic in multiple schemas. Suppose you have several models in your database and want to add a property to each one. Just create a plugin once and apply it to each Schema:

    Want to register a plugin for all schemas? The mongoose singleton has a .plugin() function that registers a plugin for every schema. For example:

    Because many plugins rely on middleware, you should make sure to apply plugins before you call or conn.model(). Otherwise, .

    You can find a full list of officially supported plugins on Mongoose’s plugins search site.

    Not only can you re-use schema functionality in your own projects, but you also reap the benefits of the Mongoose community as well. Any plugin published to and with ‘mongoose’ as an npm keyword will show up on our page.