5

I have a plugin in mongoose and for each schema i am doing the following

var user = new Schema({});
user.plugin(myplugin);
user.statics.createCustomDoc = function() {
.....
}

The problem is the createCustomDoc method is also defined in myplugin. Now i want to override createCustomDoc of myplugin with the method defined as user.statics.createCustomDoc.

Currently the method called is from the plugin not the one i wrote in user.statics.createCustomDoc.

How do i do that.?

Of course i do not want to change the name of function nor i want to remove the plugin nor i want to change code of plugin.

4

1 回答 1

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);

}
于 2015-10-28T12:35:49.063 回答