如何覆盖猫鼬插件的功能?

cod*_*ode 5 mongoose mongodb node.js mongoose-plugins

我在 mongoose 中有一个插件,对于每个模式,我都在执行以下操作

var user = new Schema({});
user.plugin(myplugin);
user.statics.createCustomDoc = function() {
.....
}
Run Code Online (Sandbox Code Playgroud)

问题是 myplugin 中也定义了 createCustomDoc 方法。现在我想createCustomDoc用定义为 user.statics.createCustomDoc 的方法覆盖myplugin。

目前调用的方法来自插件而不是我在 user.statics.createCustomDoc 中编写的方法。

我怎么做。?

当然,我不想更改函数名称,也不想删除插件,也不想更改插件代码。

kes*_*hav 0

我在覆盖猫鼬查询函数时遇到了类似的问题并尝试了类似的方法并且它有效

//store reference to original myPlugin createCustomDoc function
var createCustomDoc = user.statics.createCustomDoc;

//override that function
user.statics.createCustomDoc = function (options, callback) {
   var self = this; 
   //after your code, call original function
   createCustomDoc.call(self, options, callback);

}
Run Code Online (Sandbox Code Playgroud)