mongoose-types-ext
A package of mongoose types extensions.
Instalation
With npm
npm install --save mongoose-types-ext
Runing tests
gulp test
Usage
Just require the extensions before load your mongoose models:
var mongoose = ;mongoose;var YourSchemaDefinition = someField: type: String maxLength: 10 /* (...) */;var YourModel = mongoose;
Supported extentions
String
exactLength
: Sets a exact length string validator.
Custom error messages: You can also configure custom error messages and use the special token
{EXACT_LENGTH}
which will be replaced with the invalid value. Ex:
var rule = 4 'The length of path `{PATH}` ({VALUE}) should be equal {EXACT_LENGTH}.';var schema = n: type: String exactLength: rule )var M = mongoose;var s= n: 'teste' ;s
Number
exclusivemin
: Sets a minimum number validator not including the configurated value.
Custom error messages: You can also configure custom error messages and use the special token
{EXCLUSIVE_MIN}
which will be replaced with the invalid value. Ex:
var rule = 10 'The value of path `{PATH}` ({VALUE}) should be greater than ({EXCLUSIVE_MIN}).';var schema = n: type: Number exclusivemin: rule )var M = mongoose;var s= n: 10 ;s;
How to contribute
I am very glad to see this project living with pull requests.
LICENSE
Copyright (c) 2015 Daniel Campos
Licensed under the MIT license.