mongoose-promise-hooks

Simplifies creating promise based mongoose pre and post hooks

Usage no npm install needed!

<script type="module">
  import mongoosePromiseHooks from 'https://cdn.skypack.dev/mongoose-promise-hooks';
</script>

README

mongoose-promise-hooks

Description

Simplifies creating promise based mongoose pre and post hooks

Installation

$ npm install mongoose-promise-hooks

Usage

import hook from "mongoose-promise-hooks";

hook.pre(schema, "save", async function() {
  if (this.isNew()) {
    Email.send({
      title: `Welcome %{this.fullName}`,
      to: this.email
    });
  }
});

hook.post(schema, "save", async document => {
  const user = await User.findById(document.userId);
  // do things
  await user.save();
});

Test

npm test