2

I write a plugin that do :

module.exports = function (schema, options) {

  schema.statics.customFunction = function (criteria) {
    // Code
  };
};

And here is my Schema :

  var customPlugin = require('./plugin');
  var customSchema = new mongoose.Schema({
   // Schema
  });

  customSchema.plugin(customPlugin, {});
  var model = mongoose.model('Custom', customSchema);

  model.customFunction() // I have a undefined here

If I write my static method outside of the plugin, it is working. Is it a restriction from Mongoose?

Julien Deruere
  • 770
  • 1
  • 7
  • 11

0 Answers0