0.1.1 • Published 9 years ago

moorea-mongoose-timestamps v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
9 years ago

mongoose-timestamps

Dependency Status devDependency Status

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.