https://github.com/tarquas/mongoose-hook-createdmodified
Mongoose plugin, adding `createdAt` and `modifiedAt` timestamp fields to document. `modifiedAt` is changed on any type of update.
https://github.com/tarquas/mongoose-hook-createdmodified
Last synced: about 1 month ago
JSON representation
Mongoose plugin, adding `createdAt` and `modifiedAt` timestamp fields to document. `modifiedAt` is changed on any type of update.
- Host: GitHub
- URL: https://github.com/tarquas/mongoose-hook-createdmodified
- Owner: tarquas
- License: mit
- Created: 2015-02-05T21:50:00.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-08T18:17:04.000Z (over 10 years ago)
- Last Synced: 2025-10-03T07:58:00.414Z (about 1 month ago)
- Language: JavaScript
- Size: 203 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mongoose-hook-createdmodified
Mongoose plugin, adding `createdAt` and `modifiedAt` timestamp fields to document. `modifiedAt` is changed on any type of update.
# Installation
```shell
git clone git@github.com:tarquas/mongoose-hook-createdmodified.git mongoose-hook-createdmodified
```
# Package
```js
{
"mongoose-hook-createdmodified": "0.1.4"
}
```
# Usage
Example: enable 'createdAt' and 'modifiedAt' fields on a schema:
```js
var
mongoose = require('mongoose'),
createdModifiedPlugin = require('mongoose-hook-createdmodified'),
PersonSchema;
PersonSchema = {
name: String,
email: String
};
PersonSchema.plugin(createdModifiedPlugin, {mongoose: mongoose});
mongoose.model('Person', PersonSchema);
```
# Notes
* This plugin must be provided with an exact instance of `mongoose`, where the processing models expected to be processed, in `opts` parameter.
* This plugin updates modification time of the document on its any update operation. It's based on `mongoose-hook` plugin, so every time, any of `insert`, `update`, or `findAndModify` database API wrapper is called, the creation/modification time is updated.