You can define a field for your Foo object, for example hookEnabled , and you can check it in your hook function. Let me give an example:
Foo = new Schema({ ... hookEnabled:{ type: Boolean, required: false, default: true } ... });
And in your hook;
Foo.pre('save', function(next){ self = this if (self.hookEnabled) { // dou your job here next(); } else { // do nothing next(); } });
Before calling the save function, you can set the hookEnabled field to false,
var fooModel = new Foo(); fooModel.hookEnabled = false;
Hope this helps
Hüseyin baby
source share