mo

mongoose-observer

A small library that provides methods to listen changes in mongoose models.

Showing:

Popularity

Downloads/wk

26

GitHub Stars

9

Maintenance

Last Commit

5yrs ago

Contributors

2

Package

Dependencies

0

Size (min+gzip)

0.4KB

License

Type Definitions

Tree-Shakeable

No?

Categories

Readme

MongooseObserver

A small library that provides methods to listen changes in mongoose models.

Installation

  npm install mongoose-observer

Usage

In order to use this library, you have to create and register a model using mongoose. After that, you can register listeners to create and update events using the following API:

    mongooseObserver.register(modelName, event, callback)

Example:

  var mongooseObserver = require('mongoose-observer')
  
  mongooseObserver.register('User', 'create', function(createdUser){
    // this callback will be executed when a new user is created
    // Do something here, for example, send a email to the created user
  });

  mongooseObserver.register('User', 'update', function(updatedUser){
    // this callback will be executed when a User record is updated
    // Do something here, for example, emit changes to client via socket.io
  });

  mongooseObserver.register('User', 'remove', function(removedUser){
    // this callback will be executed when a User record is removed
    // Do something here, for example, emit changes to client via socket.io
  });

Tests

npm test

Contributing

Add unit tests for any new or changed functionality. Lint and test your code.

Release History

  • 0.1.1 Small changes to README.md
  • 0.1.0 Initial release

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100