mongoose-monitor-fields-plugin
monitor and respond to changes in your documents!
Table of Contents
Install
npm:
npm install mongoose-monitor-fields-plugin
yarn:
yarn add mongoose-monitor-fields-plugin
Basic Example Usage
const Schema = ;const monitorFields = ; const mySchema = my_field: type: String // set monitor true to have the change passed to the document level callback post save // or define a function for a field level callback post save monitor: consolelog ; mySchema; const MyModel = ; async { let myDocument = my_field: 'foo' ; await myDocument; myDocumentmy_field = 'bar'; await myDocument; // prints the following to the console // for the field level callback // {path: 'my_field', prev: 'foo', updated: 'bar'} // for the document level // [{path: 'my_field', prev: 'foo', updated: 'bar'}]};
In either field level or document level callbacks - this
refers to the newly updated document.
Special Credit
This package was heavily influenced by mongoose-plugin-diff
Contributors
Name | Website |
---|---|
Spencer Snyder | https://spencersnyder.io |