@rojo2/mongoose-date

1.1.2 • Public • Published

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)

Readme

Keywords

Package Sidebar

Install

npm i @rojo2/mongoose-date

Weekly Downloads

0

Version

1.1.2

License

MIT

Unpacked Size

7.56 kB

Total Files

4

Last publish

Collaborators

  • aitormm
  • azazeln28