mongoose-organizer
Mongoose Model Organization
The Mongoose-Organizer provides a factory utility that allows you to organize Mongoose models using declarative configuration.
project
└───models
├───User
| └───index.js (Uses mongoose-organizer to autowire the model)
| └───User.definition.js (Mongoose definition object)
| └───User.methods.js (An object of schema-methods by name)
| └───User.handlers.js (An array of event handler implementations e.g. pre-save)
| └───User.virtuals.js (An array of virtual properties)
Usage
By using the 'autowire' function, the mongoose-organizer will reflect over your model's path and load in model components.
// Index.jslet organizer = ;moduleexports = organizer;
Non-Autowiring Usage
By using the 'makeSchema' function, the mongoose-organizer can use inline configuration.
let organizer = ;moduleexports =
Configuration Options
- name (required) - The name of the model
- definition / definitionPath (required) - The explicit Mongoose schema definition, or a path to the schema definition.
- options / optionsPath (optional) - The explicit Mongoose schema options, or a path to the schema options. Default value is:
toJSON: virtual: true toObject: virtuals: true
- methods / methodsPath (optional) - An object of methods by name.
moduleexports = { ... }
- virtuals / virtualsPath (optional) - An array of virtual property definitions
moduleexports = name: '<virtual path>' get: <optional getter
- handlers / handlersPath (optional) - An array of event handler definitions
moduleexports = type: 'pre' event: 'save' description: '<a useful description of the handler>' {...} ;