Mongoose plugin, adding createdAt
and modifiedAt
timestamp fields to document. modifiedAt
is changed on any type of update.
git clone [email protected]:tarquas/mongoose-hook-createdmodified.git mongoose-hook-createdmodified
{
"mongoose-hook-createdmodified": "0.1.4"
}
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);
-
This plugin must be provided with an exact instance of
mongoose
, where the processing models expected to be processed, inopts
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 ofinsert
,update
, orfindAndModify
database API wrapper is called, the creation/modification time is updated.