mongoose-promise-hooks
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

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

Package Sidebar

Install

npm i mongoose-promise-hooks

Weekly Downloads

65

Version

1.0.2

License

MIT

Unpacked Size

20.6 kB

Total Files

15

Last publish

Collaborators

  • kilhage