Mongoose Defaults
Plugin for mongoose which sets up all default values for fields if default values were not provided.
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: {},