node.js - Display multiple validation errors for Mongoose model -


if have schema:

var userschema = schema(     {name : {         type: string     } });  userschema.path('name').validate(function(value) {     return value.length > 4; }, 'name short');  userschema.path('name').validate(function(value) {     return hasnonumbers(value); }, 'name cannot have numbers');  var user = mongoose.model('user', userschema); 

then create model , run validate function:

var newuser = new user({name: '1da'});  newuser.validate(function(err) {     console.log(err.errors.name); }) 

this logs first error message 'name short'. however, name property fails both validation requirements. there way display both error message?

thanks

apparently feature isn't implemented in v3 of mongoose.

https://github.com/learnboost/mongoose/pull/1214#issuecomment-15746525

when v4 become stable, i'll give try again.

until then, module seems solve issue:

https://github.com/szdc/mongoose-validate-all


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -