moorea-mongoose-timestamps
v0.1.1
Published
simple timestamps plugin for Mongoose
Downloads
7
Readme
mongoose-timestamps
simple timestamps plugin for Mongoose
Installation
npm install moorea-mongoose-timestamps
Usage
'use strict';
var
mongoose = require('mongoose'),
timestamps = require('moorea-mongoose-timestamps');
var
kittySchema = mongoose.Schema({ name: String });
kittySchema.plugin(timestamps);
module.exports = mongoose.model('Kitten', kittySchema);
A timestamps
object is added to the document, with two Date properties: createdAt
and modifiedAt
.
{
timestamps: {
createdAt : Date,
modifiedAt: Date
}
}
createdAt
is update every time a new document is created, modifiedAt
is updated every time the document is changed.