mongoose-defaults

3.0.1 • Public • Published

Mongoose Defaults

Plugin for mongoose which sets up all default values for fields if default values were not provided.

npm version npm downloads

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: {},

Package Sidebar

Install

npm i mongoose-defaults

Weekly Downloads

4

Version

3.0.1

License

ISC

Unpacked Size

2.99 kB

Total Files

3

Last publish

Collaborators

  • hasebsiddiqui