mongoose validate check database -


is possible have validation in mongoose checks database?

i need have this

var validemail = require('../helpers/validate/email'); var validdoctor = require('../helpers/validate/doctors'); var schema = mongoose.schema({   email: { type: string, validate: [validemail, "invalid email"],   doctor: {type: string, validate: [validdoctor, "invalid doctor"] } 

and validdoctor like:

module.exports = function (doctor) {   doctors.findone({email:doctor}, function (err, found) {     return (found); }); 

i have tried put scripts in pre , post hooks, , code getting sloppy. have have validation this

you need async validation accepts second argument callback function called either true or false denoting successful or failed validation respectively

module.exports = function (doctor, done) {   doctors.findone({email:doctor}, function (err, found) {     if(found) done(true);     else done(false); }); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -