私はプラグインを書きます:
module.exports = function (schema, options) {
schema.statics.customFunction = function (criteria) {
// Code
};
};
そして、ここに私のスキーマがあります:
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
プラグインの外部で静的メソッドを記述した場合、それは機能しています。Mongooseからの制限ですか?