Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/muzk/mongoose-observer
A small library that provides methods to listen changes in mongoose models.
https://github.com/muzk/mongoose-observer
javascript mongoose mongoose-model
Last synced: 3 months ago
JSON representation
A small library that provides methods to listen changes in mongoose models.
- Host: GitHub
- URL: https://github.com/muzk/mongoose-observer
- Owner: muZk
- License: mit
- Created: 2014-09-17T14:35:42.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-12-27T14:37:20.000Z (about 8 years ago)
- Last Synced: 2024-10-11T12:20:11.257Z (3 months ago)
- Topics: javascript, mongoose, mongoose-model
- Language: JavaScript
- Size: 7.81 KB
- Stars: 10
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
MongooseObserver
=========A small library that provides methods to listen changes in mongoose models.
## Installation
```shell
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:```js
mongooseObserver.register(modelName, event, callback)
```Example:
```js
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