mongoose-default
v3.0.2
Published
Plugin for mongoose which sets up all default values for fields if default values were not provided
Downloads
10
Maintainers
Readme
Mongoose Default
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-default
Versioning
We use SemVer for versioning
Usage
const mongoosedefault = require('mongoose-default');
//Set default values of all mongoose fields to Predefined Defaults.
Schema.plugin(mongoosedefault);
//Set default values of all mongoose fields except String to Predefined Defaults. Set the default
//of all String fields to "defaultValue".
Schema.plugin(mongoosedefault,{String:"defaultValue"});
Predefined Defaults:
String: "",
Number: 0,
Date: new Date(),
Boolean: false,
Number: 0,
String: "",
Array: [],
Embedded: {},