0.0.2 • Published 6 years ago

motime v0.0.2

Weekly downloads
13
License
MIT
Repository
github
Last release
6 years ago

Motime --- mongoose timestamp plugin

Used to add createdAt and updatedAt for documents before save or update, support following mongoose operation:

  • Document.save()
  • Model.create()
  • Model.insertMany()
  • Model.findOneAndUpdate()
  • Model.findByIdAndUpdate()
  • Model.update()
  • Model.updateMany()
  • Model.updateOne()

Install

npm install motime --save

Usage

const timePlugin = require('motime');
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const UserSchema = new Schema({
  name: String,
  email: String
});

UserSchema.plugin(timePlugin);
mongoose.model('User', UserSchema);

You can also change the field name easily:

UserSchema.plugin(timePlugin, {
  createdAt: 'create_at',
  updatedAt: 'updated_at'
});

License

MIT

0.0.2

6 years ago

0.0.1

6 years ago