mongoose-hook-createdmodified

0.1.4 • Public • Published

mongoose-hook-createdmodified

Mongoose plugin, adding createdAt and modifiedAt timestamp fields to document. modifiedAt is changed on any type of update.

Installation

git clone git@github.com:tarquas/mongoose-hook-createdmodified.git mongoose-hook-createdmodified

Package

{
  "mongoose-hook-createdmodified": "0.1.4"
}

Usage

Example: enable 'createdAt' and 'modifiedAt' fields on a schema:

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.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.4
    1,140
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.4
    1,140
  • 0.1.3
    1

Package Sidebar

Install

npm i mongoose-hook-createdmodified

Weekly Downloads

1,141

Version

0.1.4

License

MIT

Last publish

Collaborators

  • tarquas