Skip to content

Instantly share code, notes, and snippets.

Last active Nov 12, 2017
What would you like to do?
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 =; = wrapAsync(save, '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment