LearnBoost/mongoose — Issue #763: Min validator is fail, when number is null
Author: btamas
Created: 2012-03-07 18:38:13+00:00
State: open

I have a schema with a number path:

year:
type: Number
min: 1900
required: false

This path is not required, so i can insert null object, but min validator failed:

{
message: 'Validator "min" failed for path year',
name: 'ValidatorError',
path: 'year',
type: 'min'
}

I think it is not the correct working, or am I wrong? I think the workaround is

In file schema/number.js:

54: this.validators.push([function(v){
55: return v >= value;
56: }, 'min']);

change to

54: this.validators.push([function(v){
55: return v === null || v >= value;
56: }, 'min']);

(The max validator work similary than min!)