Mongoose returns Validation Error on save from Post Request [duplicate]req.body empty on postsMongoose: validation error path is requiredHow is an HTTP POST request made in node.js?Unclear Mongoose errorNodeJs, Mocha and Mongooseafter saving in mongoose strict : false,can't edit after findOne()Mongoose validation Crash on herokupost with angular gives error: possibly unhandled rejectionMongoose, can't print products from databaseError module.exports mongooseValidationError: mongoose validation failedCastError: Cast to ObjectId failed for value “5be86bf8170c2c22f8bb93a6 ” at path “_id” for model “Page”

How to evaluate sum with one million summands?

Windows OS quantum vs. SQL OS Quantum

We are two immediate neighbors who forged our own powers to form concatenated relationship. Who are we?

Advantages/Disadvantages of Compiling as Both C and C++?

Is it a good idea to copy a trader when investing?

Why does increasing the sampling rate make implementing an anti-aliasing filter easier?

Why was the ancient one so hesitant to teach Dr Strange the art of sorcery

Was the Highlands Ranch shooting the 115th mass shooting in the US in 2019

spatiotemporal regression

How can a demonic viral infection spread throughout the body without being noticed?

Is there some sort of formula to determine how many bricks I would need to build a completely new structure?

How to make a language evolve quickly?

Is a vertical stabiliser needed for straight line flight in a glider?

Why can't I prove summation identities without guessing?

Why should password hash verification be time consistent?

How to get the IP of a user who executed a command?

No such column 'DeveloperName' on entity 'RecordType' after Summer '19 release on sandbox

Why did they go to Dragonstone?

Can 'sudo apt-get remove [write]' destroy my Ubuntu?

How to find the tex encoding of specific fonts?

What was the notion of limit that Newton used?

Why do Thanos' punches not kill Captain America or at least cause vital wounds?

What is wrong with my code? RGB potentiometer

What can cause an unfrozen indoor copper drain pipe to crack?



Mongoose returns Validation Error on save from Post Request [duplicate]


req.body empty on postsMongoose: validation error path is requiredHow is an HTTP POST request made in node.js?Unclear Mongoose errorNodeJs, Mocha and Mongooseafter saving in mongoose strict : false,can't edit after findOne()Mongoose validation Crash on herokupost with angular gives error: possibly unhandled rejectionMongoose, can't print products from databaseError module.exports mongooseValidationError: mongoose validation failedCastError: Cast to ObjectId failed for value “5be86bf8170c2c22f8bb93a6 ” at path “_id” for model “Page”






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0
















This question already has an answer here:



  • req.body empty on posts

    15 answers



  • Mongoose: validation error path is required

    2 answers



I have been trying to get an insert an array in nodejs but i havent been able to do so an error keeps coming up about the path



I want to insert an array to be stored on mongo db atlas but i keep getting an error this error never existed, untill I introduced IDSchema into the code



/*model file*/
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

require('mongoose-currency').loadType(mongoose);


var IDschema = new Schema(
vanId: type: String, required: true,
driverId: type: String, required: true
)

var driverschema = new Schema(
_id: mongoose.Schema.Types.ObjectId,
name: type: String, required: true,
age: type: String, required: true,
phonenumber: type: String, required: true,
address: type: String, required: true,
dob: type: String, required: true,
designation: type: String, required: true,
ID:[IDschema]

);


var Driver = mongoose.model('Driver', driverschema);

module.exports = Driver

/*routes file*/

const express = require('express');
const router = express.Router();
const mongoose = require('mongoose');

const Driver = require('../model/driverdetails');




router.post('/driverdetails', function(req, res)
const driverschema = new Driver(
_id: new mongoose.Types.ObjectId(),
name: req.body.name,
age: req.body.age,
phonenumber: req.body.phonenumber,
address: req.body.address,
dob: req.body.dob,
designation: req.body.designation,
ID: req.body.ID

);
driverschema.save()
.then(result =>
console.log(result);
res.status(200).json(result);
)
.catch(err =>
console.log(err);
res.status(500).json(
error: err
);
)
);



module.exports = router;


this is the error i get




{ name:
ValidatorError: Path name is required.
at new ValidatorError (C:projectsJWTnode_modulesmongooseliberrorvalidator.js:29:11)
at validate (C:projectsJWTnode_modulesmongooselibschematype.js:930:13)
at C:projectsJWTnode_modulesmongooselibschematype.js:983:11
at Array.forEach ()
at SchemaString.SchemaType.doValidate (C:projectsJWTnode_modulesmongooselibschematype.js:939:19)
at C:projectsJWTnode_modulesmongooselibdocument.js:1936:9
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
message: 'Path name is required.',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'name',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true ,











share|improve this question















marked as duplicate by Neil Lunn node.js
Users with the  node.js badge can single-handedly close node.js questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 23 at 9:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • ValidatorError: Path name is required. is because the name field when you do new Driver(...) is empty, and it cannot be by your schema rules. The most likely reason is there is no content at all in req.body. Check you actually sent some data, and check the encoding type sent with the request. You probably want application/json and you did not set it. Happens a lot with people using Postman for the first time.

    – Neil Lunn
    Mar 23 at 9:56











  • Try letting mongoose take care of the _id generation. eg. delete the lines with _id in both the declaration and the use

    – Jonas Praem
    Mar 23 at 9:56

















0
















This question already has an answer here:



  • req.body empty on posts

    15 answers



  • Mongoose: validation error path is required

    2 answers



I have been trying to get an insert an array in nodejs but i havent been able to do so an error keeps coming up about the path



I want to insert an array to be stored on mongo db atlas but i keep getting an error this error never existed, untill I introduced IDSchema into the code



/*model file*/
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

require('mongoose-currency').loadType(mongoose);


var IDschema = new Schema(
vanId: type: String, required: true,
driverId: type: String, required: true
)

var driverschema = new Schema(
_id: mongoose.Schema.Types.ObjectId,
name: type: String, required: true,
age: type: String, required: true,
phonenumber: type: String, required: true,
address: type: String, required: true,
dob: type: String, required: true,
designation: type: String, required: true,
ID:[IDschema]

);


var Driver = mongoose.model('Driver', driverschema);

module.exports = Driver

/*routes file*/

const express = require('express');
const router = express.Router();
const mongoose = require('mongoose');

const Driver = require('../model/driverdetails');




router.post('/driverdetails', function(req, res)
const driverschema = new Driver(
_id: new mongoose.Types.ObjectId(),
name: req.body.name,
age: req.body.age,
phonenumber: req.body.phonenumber,
address: req.body.address,
dob: req.body.dob,
designation: req.body.designation,
ID: req.body.ID

);
driverschema.save()
.then(result =>
console.log(result);
res.status(200).json(result);
)
.catch(err =>
console.log(err);
res.status(500).json(
error: err
);
)
);



module.exports = router;


this is the error i get




{ name:
ValidatorError: Path name is required.
at new ValidatorError (C:projectsJWTnode_modulesmongooseliberrorvalidator.js:29:11)
at validate (C:projectsJWTnode_modulesmongooselibschematype.js:930:13)
at C:projectsJWTnode_modulesmongooselibschematype.js:983:11
at Array.forEach ()
at SchemaString.SchemaType.doValidate (C:projectsJWTnode_modulesmongooselibschematype.js:939:19)
at C:projectsJWTnode_modulesmongooselibdocument.js:1936:9
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
message: 'Path name is required.',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'name',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true ,











share|improve this question















marked as duplicate by Neil Lunn node.js
Users with the  node.js badge can single-handedly close node.js questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 23 at 9:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • ValidatorError: Path name is required. is because the name field when you do new Driver(...) is empty, and it cannot be by your schema rules. The most likely reason is there is no content at all in req.body. Check you actually sent some data, and check the encoding type sent with the request. You probably want application/json and you did not set it. Happens a lot with people using Postman for the first time.

    – Neil Lunn
    Mar 23 at 9:56











  • Try letting mongoose take care of the _id generation. eg. delete the lines with _id in both the declaration and the use

    – Jonas Praem
    Mar 23 at 9:56













0












0








0









This question already has an answer here:



  • req.body empty on posts

    15 answers



  • Mongoose: validation error path is required

    2 answers



I have been trying to get an insert an array in nodejs but i havent been able to do so an error keeps coming up about the path



I want to insert an array to be stored on mongo db atlas but i keep getting an error this error never existed, untill I introduced IDSchema into the code



/*model file*/
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

require('mongoose-currency').loadType(mongoose);


var IDschema = new Schema(
vanId: type: String, required: true,
driverId: type: String, required: true
)

var driverschema = new Schema(
_id: mongoose.Schema.Types.ObjectId,
name: type: String, required: true,
age: type: String, required: true,
phonenumber: type: String, required: true,
address: type: String, required: true,
dob: type: String, required: true,
designation: type: String, required: true,
ID:[IDschema]

);


var Driver = mongoose.model('Driver', driverschema);

module.exports = Driver

/*routes file*/

const express = require('express');
const router = express.Router();
const mongoose = require('mongoose');

const Driver = require('../model/driverdetails');




router.post('/driverdetails', function(req, res)
const driverschema = new Driver(
_id: new mongoose.Types.ObjectId(),
name: req.body.name,
age: req.body.age,
phonenumber: req.body.phonenumber,
address: req.body.address,
dob: req.body.dob,
designation: req.body.designation,
ID: req.body.ID

);
driverschema.save()
.then(result =>
console.log(result);
res.status(200).json(result);
)
.catch(err =>
console.log(err);
res.status(500).json(
error: err
);
)
);



module.exports = router;


this is the error i get




{ name:
ValidatorError: Path name is required.
at new ValidatorError (C:projectsJWTnode_modulesmongooseliberrorvalidator.js:29:11)
at validate (C:projectsJWTnode_modulesmongooselibschematype.js:930:13)
at C:projectsJWTnode_modulesmongooselibschematype.js:983:11
at Array.forEach ()
at SchemaString.SchemaType.doValidate (C:projectsJWTnode_modulesmongooselibschematype.js:939:19)
at C:projectsJWTnode_modulesmongooselibdocument.js:1936:9
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
message: 'Path name is required.',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'name',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true ,











share|improve this question

















This question already has an answer here:



  • req.body empty on posts

    15 answers



  • Mongoose: validation error path is required

    2 answers



I have been trying to get an insert an array in nodejs but i havent been able to do so an error keeps coming up about the path



I want to insert an array to be stored on mongo db atlas but i keep getting an error this error never existed, untill I introduced IDSchema into the code



/*model file*/
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

require('mongoose-currency').loadType(mongoose);


var IDschema = new Schema(
vanId: type: String, required: true,
driverId: type: String, required: true
)

var driverschema = new Schema(
_id: mongoose.Schema.Types.ObjectId,
name: type: String, required: true,
age: type: String, required: true,
phonenumber: type: String, required: true,
address: type: String, required: true,
dob: type: String, required: true,
designation: type: String, required: true,
ID:[IDschema]

);


var Driver = mongoose.model('Driver', driverschema);

module.exports = Driver

/*routes file*/

const express = require('express');
const router = express.Router();
const mongoose = require('mongoose');

const Driver = require('../model/driverdetails');




router.post('/driverdetails', function(req, res)
const driverschema = new Driver(
_id: new mongoose.Types.ObjectId(),
name: req.body.name,
age: req.body.age,
phonenumber: req.body.phonenumber,
address: req.body.address,
dob: req.body.dob,
designation: req.body.designation,
ID: req.body.ID

);
driverschema.save()
.then(result =>
console.log(result);
res.status(200).json(result);
)
.catch(err =>
console.log(err);
res.status(500).json(
error: err
);
)
);



module.exports = router;


this is the error i get




{ name:
ValidatorError: Path name is required.
at new ValidatorError (C:projectsJWTnode_modulesmongooseliberrorvalidator.js:29:11)
at validate (C:projectsJWTnode_modulesmongooselibschematype.js:930:13)
at C:projectsJWTnode_modulesmongooselibschematype.js:983:11
at Array.forEach ()
at SchemaString.SchemaType.doValidate (C:projectsJWTnode_modulesmongooselibschematype.js:939:19)
at C:projectsJWTnode_modulesmongooselibdocument.js:1936:9
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
message: 'Path name is required.',
name: 'ValidatorError',
properties: [Object],
kind: 'required',
path: 'name',
value: undefined,
reason: undefined,
[Symbol(mongoose:validatorError)]: true ,






This question already has an answer here:



  • req.body empty on posts

    15 answers



  • Mongoose: validation error path is required

    2 answers







node.js mongoose






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 9:59









Neil Lunn

102k23183189




102k23183189










asked Mar 23 at 9:50









Mudassir AhmedMudassir Ahmed

1




1




marked as duplicate by Neil Lunn node.js
Users with the  node.js badge can single-handedly close node.js questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 23 at 9:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Neil Lunn node.js
Users with the  node.js badge can single-handedly close node.js questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 23 at 9:57


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • ValidatorError: Path name is required. is because the name field when you do new Driver(...) is empty, and it cannot be by your schema rules. The most likely reason is there is no content at all in req.body. Check you actually sent some data, and check the encoding type sent with the request. You probably want application/json and you did not set it. Happens a lot with people using Postman for the first time.

    – Neil Lunn
    Mar 23 at 9:56











  • Try letting mongoose take care of the _id generation. eg. delete the lines with _id in both the declaration and the use

    – Jonas Praem
    Mar 23 at 9:56

















  • ValidatorError: Path name is required. is because the name field when you do new Driver(...) is empty, and it cannot be by your schema rules. The most likely reason is there is no content at all in req.body. Check you actually sent some data, and check the encoding type sent with the request. You probably want application/json and you did not set it. Happens a lot with people using Postman for the first time.

    – Neil Lunn
    Mar 23 at 9:56











  • Try letting mongoose take care of the _id generation. eg. delete the lines with _id in both the declaration and the use

    – Jonas Praem
    Mar 23 at 9:56
















ValidatorError: Path name is required. is because the name field when you do new Driver(...) is empty, and it cannot be by your schema rules. The most likely reason is there is no content at all in req.body. Check you actually sent some data, and check the encoding type sent with the request. You probably want application/json and you did not set it. Happens a lot with people using Postman for the first time.

– Neil Lunn
Mar 23 at 9:56





ValidatorError: Path name is required. is because the name field when you do new Driver(...) is empty, and it cannot be by your schema rules. The most likely reason is there is no content at all in req.body. Check you actually sent some data, and check the encoding type sent with the request. You probably want application/json and you did not set it. Happens a lot with people using Postman for the first time.

– Neil Lunn
Mar 23 at 9:56













Try letting mongoose take care of the _id generation. eg. delete the lines with _id in both the declaration and the use

– Jonas Praem
Mar 23 at 9:56





Try letting mongoose take care of the _id generation. eg. delete the lines with _id in both the declaration and the use

– Jonas Praem
Mar 23 at 9:56












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Obelisk of Theodosius Contents History Description Notes Bibliography Further reading External links Navigation menuAge of spirituality : late antique and early Christian art, third to seventh centuryOver 60 picturesObelisks of the World41°00′21.24″N 28°58′31.43″E / 41.0059000°N 28.9753972°E / 41.0059000; 28.97539727724550-7235741376235741376

밀양 대씨 역사 각주 함께 보기 둘러보기 메뉴밀양 대씨

1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴