我写了一个插件:
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的限制吗?