productModel.js:
const mongoose = require("mongoose");
const productSchema = new mongoose.Schema({
name: {
type: String,
required: true,//err here.
},
})
There is an answer at link but those do not fix my error.
Here is the request that I send:
http://localhost:4000/api/v1/product/new (POST request with JSON content)
JSON:
{
"name":"Vaseline petrolatum Jelly"
}
The above code gives the below error:
this.$__.validationError = new ValidationError(this);
^
ValidationError: Product validation failed: name: Path name
is required.
at Document.invalidate (C:UsersDELLDownloadsreact-learnnode_modulesmongooselibdocument.js:3289:32)
at C:UsersDELLDownloadsreact-learnnode_modulesmongooselibdocument.js:3050:17
at C:UsersDELLDownloadsreact-learnnode_modulesmongooselibschemaType.js:1388:9
at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
errors: {
name: ValidatorError: Path name
is required.
at validate (C:UsersDELLDownloadsreact-learnnode_modulesmongooselibschemaType.js:1385:13)
at SchemaType.doValidate (C:UsersDELLDownloadsreact-learnnode_modulesmongooselibschemaType.js:1369:7)
at C:UsersDELLDownloadsreact-learnnode_modulesmongooselibdocument.js:3042:18
at process.processTicksAndRejections (node:internal/process/task_queues:77:11) {
properties: {
validator: [Function (anonymous)],
message: ‘Path name
is required.’,
type: ‘required’,
path: ‘name’,
fullPath: undefined,
value: undefined
},
kind: ‘required’,
path: ‘name’,
value: undefined,
reason: undefined,
[Symbol(mongoose#validatorError)]: true
}
},
_message: ‘Product validation failed’
}
I tried the solutions at link but none of them worked for me.
ahmed khan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1