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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현