Skip to content

Instantly share code, notes, and snippets.

@vdeturckheim
Last active November 12, 2017 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdeturckheim/c6dd297d34d9786531260df30b2b9282 to your computer and use it in GitHub Desktop.
Save vdeturckheim/c6dd297d34d9786531260df30b2b9282 to your computer and use it in GitHub Desktop.
const proto = Object.getPrototypeOf(Mongoose);
const exec = proto.Query.prototype.exec;
proto.Query.prototype.exec = wrapAsync(exec); // wrapping exec will wrap most mongoose call
const Model = proto.Model; // we still need to wrap save and remove here since they do not work like the other methods in mongoose.
const remove = Model.prototype.remove;
Model.prototype.remove = wrapAsync(remove, 'mongoose.remove');
const save = Model.prototype.save;
Model.prototype.save = wrapAsync(save, 'mongoose.save');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment