I dont know why i am getting a validator error response. I have tried to debug as much as possible but i cant see to find where the problem is. I have used the exact names i have used in my schema but still im getting the error in both postman and rest client My server.js looks like this:
const app = express()
const mongoose = require('mongoose')
const dotenv= require('dotenv')
const routesUrls=require('./routes/routes')
const cors = require('cors')
dotenv.config()
mongoose.connect(process.env.DATABASE_ACCESS, () =>console.log("Database Connected"))
app.use(express.json())
app.use(cors())
app.use('/app', routesUrls)
app.listen(4000, () => console.log("server is up and running"))
My routes.js
const router = express.Router()
const signupTemplateCopy = require('../models/SignUpModels')
router.post('/signup/', (request,response) =>{
const SignedupUser = new signupTemplateCopy({
fullname:request.body.fullname,
username:request.body.username,
email:request.body.email,
password:request.body.password
})
SignedupUser.save().then(data =>{
response.json(data)})
.catch(error =>{
response.json(error)
})
})
module.exports = router ```
The Schema looks like this
```const mongoose = require('mongoose')
const signupTemplate = new mongoose.Schema({
fullname:{
type:String,
required:true
},
username:{
type:String,
required:true
},
email:{
type:String,
required:true
},
password:{
type:String,
required:true
},
date:{
type:Date,
default:Date.now
}
})
module.exports = mongoose.model('mytable', signupTemplate)
The error
"errors": {
"fullname": {
"name": "ValidatorError",
"message": "Path `fullname` is required.",
"properties": {
"message": "Path `fullname` is required.",
"type": "required",
"path": "fullname"
},
"kind": "required",
"path": "fullname"
},
"username": {
"name": "ValidatorError",
"message": "Path `username` is required.",
"properties": {
"message": "Path `username` is required.",
"type": "required",
"path": "username"
},
"kind": "required",
"path": "username"
},
"email": {
"name": "ValidatorError",
"message": "Path `email` is required.",
"properties": {
"message": "Path `email` is required.",
"type": "required",
"path": "email"
},
"kind": "required",
"path": "email"
},
"password": {
"name": "ValidatorError",
"message": "Path `password` is required.",
"properties": {
"message": "Path `password` is required.",
"type": "required",
"path": "password"
},
"kind": "required",
"path": "password"
}
},```
"_message": "mytable validation failed",
"message": "mytable validation failed: fullname: Path `fullname` is required., username: Path `username` is required., email: Path `email` is required., password: Path `password` is required."
}
API? In what format are you trying to send your data?