Mongoose updated_at Plugin
A simple Mongoose plugin which adds
updatedAt
date attribute to models that include our plugin.
Installation
npm install mongoose-updated_at --save
Usage
First of all, add to your model a createdAt attribute.
createdAt: { type: Date, default: Date.now }
Then require mongoose-updated_at
plugin on your schema file.
var updatedTimestamp = ; var UserSchema = name: String createdAt: type: Date default: Datenow ; UserSchema; moduleexports = mongoose;
The User model will now have an updatedAt
attribute, which will be updated
every time you save your document.
If you already have timestamps defined on your models with different names, you can setup the plugin on these attributes and work with them instead of adding new ones.
mongoose;