Call to a static method to a schema inside a plugin in Mongoose

不羁岁月 提交于 2019-12-11 02:03:26

问题


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?

来源:https://stackoverflow.com/questions/27335431/call-to-a-static-method-to-a-schema-inside-a-plugin-in-mongoose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!