问题
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