我有一个mongoose插件,我为每个架构做了以下
var user = new Schema({});
user.plugin(myplugin);
user.statics.createCustomDoc = function() {
.....
}
问题是myClugin中也定义了createCustomDoc方法。
现在我想用定义为user.statics.createCustomDoc的方法覆盖myplugin的createCustomDoc
。
目前调用的方法来自插件而不是我在user.statics.createCustomDoc中编写的方法。
我该怎么做。?
当然我不想更改功能名称,也不想删除插件,也不想更改插件代码。
答案 0 :(得分:0)
我在覆盖mongoose查询函数时遇到了类似的问题,并尝试了类似的东西并且它可以正常工作
//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);
}