mongoose-plugin-modified
A mongoose.js plugin to capture document updates with timestamp and optional user identifier.
The modification date is updated pre-validation if a monitored field has been modified
Installation
npm i --save mongoose-plugin-modified
API Reference
Example
var modifiedPlugin = ;var schema = ;schema;
mongoose-plugin-modified~options
Kind: inner property of mongoose-plugin-modified
Param | Type | Default | Description |
---|---|---|---|
[options] | object |
||
options.optionKey | string |
"modified" |
the path options key to mark paths for inclusion in monitoring for modification. If no paths are tagged, document modification is monitored. |
[options.date] | object |
options for configuring the path for storing the date. | |
options.date.path | string |
"modified.date" |
the path for storing the modified date. |
options.date.options | object |
property options to set (type will always be Date ). (e.g. {select: false}) |
|
[options.by] | object |
options for configuring the path for storing the modifier. | |
options.by.path | string |
"modified.by" |
the path for storing the document modifier. |
options.by.ref | string |
the reference model to use (e.g. {by: {ref: 'ModelRefName'}}) |
|
options.by.options | object |
property options to set (if not a reference the type will always be String ). (e.g. {select: false}) |
Examples
With Monitoring Entire Document
var modifiedPlugin = ;var schema = ;schema; var Foo = mongoose;var foo = Foo; // foo.modified --> {}foofoo = 'My update'; // foo.modified --> {}foo; // foo.modified --> {date: 'Wed May 05 2015 12:05:50 GMT-0400 (EDT)'}
With Monitoring Selected Fields
var modifiedPlugin = ;var schema = ;schema; var Foo = mongoose;var foo = Foo; // foo.modified --> {}foofoo = 'My update'; // foo.modified --> {}foo; // foo.modified --> {date: 'Wed May 05 2015 12:05:50 GMT-0400 (EDT)'} foobar = 'My other update'; // foo.modified --> {date: 'Wed May 05 2015 12:05:50 GMT-0400 (EDT)'}foo; // foo.modified --> {date: 'Wed May 05 2015 12:05:50 GMT-0400 (EDT)'} // modified.date is not updated
License
Apache 2.0