Connection.prototype.plugin()

Parameters
  • fn «Function» plugin callback

  • [opts] «Object» optional options

Returns:
  • «Connection» this

Declares a plugin executed on all schemas you pass to conn.model()

Equivalent to calling .plugin(fn) on each schema you create.

Example:

  1. const db = mongoose.createConnection('mongodb://localhost:27017/mydb');
  2. db.plugin(() => console.log('Applied'));
  3. db.plugins.length; // 1
  4. db.model('Test', new Schema({})); // Prints "Applied"