Skip to content

ES6 Mongoose creation and modification date plugin

Notifications You must be signed in to change notification settings

rojo2/mongoose-date

Repository files navigation

Mongoose Date plugin

Travis CI

This small plugin adds two new properties (modified and created) to the schema.

How to use it

import date from "@rojo2/mongoose-date";
import password from "@rojo2/mongoose-password";
import { Schema } from "mongoose";

const UserSchema = new Schema({
  email: {
    type: String,
    unique: true
  }
});

UserSchema.plugin(date);
UserSchema.plugin(password);

If you don't like created and modified names, you can change how this plugin deals with that properties just by setting a new name on the plugin options parameter as follows:

import date from "@rojo2/mongoose-date";
import password from "@rojo2/mongoose-password";
import { Schema } from "mongoose";

const UserSchema = new Schema({
  email: {
    type: String,
    unique: true
  }
});

UserSchema.plugin(date, {
  created: "creationDate",
  modified: "modificationDate"
});
UserSchema.plugin(password);

What if you already had those properties on your schema? Well, no problem, if you already had those properties in your schema this plugin will throw an Error notifying you that you already had those properties defined.

Made with ❤️ by ROJO 2 (http://rojo2.com)

About

ES6 Mongoose creation and modification date plugin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published