node.js - ValidationError: Visiteur validation failed at MongooseError -


i have problem post requests... want create new visiteur in database:

app.js
const express = require('express'); const app = express(); const bodyparser = require('body-parser'); const mongoose = require('mongoose');

        app.use(express.static(__dirname+'/client'));         app.use(bodyparser.json());         visiteur =require('./models/visiteurm');         mongoose.connect('mongodb://localhost/virtuordb');         var db = mongoose.connection;         app.post('/api/visiteurs', (req, res) => {         var visiteur = req.body;         visiteur.addvisiteur(visiteur, (err, visiteur) => {         if(err){             throw err;         }         res.json(visiteur);         });         }); 

the model visiteurm.js: schema:

    const mongoose = require('mongoose');      // book schema     const visiteurschema = mongoose.schema({          nom:{             type: string,             required: true         },         prenom:{             type: string,             required: true         },         type:{             type:string,             require: true         },         email:{             type: string,             required: true         },         password:{             type: string,             required: true         },         rpassword:{             type: string,             required: true         },         create_date:{             type: date,             default: date.now         }     });     const visiteur = module.exports = mongoose.model('visiteur',      visiteurschema);     // add visiteur     module.exports.addvisiteur = (visiteur, callback) => {         visiteur.create(visiteur, callback);     } 

the error: validation failed though don't have validation middleware nodejs

    running on port 8080...      events.js:160           throw er; // unhandled 'error' event           ^     validationerror: visiteur validation failed         @ mongooseerror.validationerror (c:\users\sofien\documents\test\node_modules\mongoose\lib\error\validation.js:23:11)         @ model.document.invalidate (c:\users\sofien\documents\test\node_modules\mongoose\lib\document.js:1535:32)         @ c:\users\sofien\documents\test\node_modules\mongoose\lib\document.js:1410:17         @ validate (c:\users\sofien\documents\test\node_modules\mongoose\lib\schematype.js:707:7)         @ c:\users\sofien\documents\test\node_modules\mongoose\lib\schematype.js:752:11         @ array.foreach (native)         @ schemastring.schematype.dovalidate (c:\users\sofien\documents\test\node_modules\mongoose\lib\schematype.js:712:19)         @ c:\users\sofien\documents\test\node_modules\mongoose\lib\document.js:1408:9         @ _combinedtickcallback (internal/process/next_tick.js:67:7)         @ process._tickcallback (internal/process/next_tick.js:98:9) 


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -