3.0.1 • Published 3 years ago

mongoose-defaults v3.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

Mongoose defaults

This plugin sets default value for all fields if default values were not provided. It also sets the defaults of embedded docs/sub docs recursively.

Install

  npm i mongoose-defaults

Versioning

We use SemVer for versioning

Usage

  const mongoosedefaults = require('mongoose-defaults');

  //Set default values of all mongoose fields to Predefined Defaults.
  Schema.plugin(mongoosedefaults);

  //Set default values of all mongoose fields except String to Predefined Defaults. Set the default
  //of all String fields to "defaultValue".
  Schema.plugin(mongoosedefaults,{String:"defaultValue"});

Predefined Defaults:

  String: "",
  Number: 0,
  Date: new Date(),
  Boolean: false,
  Number: 0,
  String: "",
  Array: [],
  Embedded: {},