Skip to content
Jean-Baptiste Musso edited this page Oct 28, 2013 · 1 revision

Plugins add a set of methods to existing schemas. They behave pretty much the same in Mogwai as they do in Mongoose.

Defining a plugin

plugin.js file:

module.exports = function(schema, options) {
  schema.method("doSomething", function(callback) {
    // ...
  });

  schema.static("doMoreStuff", function(callback) {
    // ...
  });
}

Adding a plugin to an existing Schema

var mogwai = require("mogwai");
var myplugin = require("./path/to/my/plugin");

UserSchema = new mogwai.Schema(/*...*/)

// Attach plugin to UserSchema
UserSchema.plugin(myplugin);

Please note that plugins currently do not support attached .groovy files, but this should change in the future.

Clone this wiki locally