Reputation: 236
The question is pretty much self explanatory. I have created a backend for MongoDB using nodeJS. Here is the link to my entire backend project so you can replicate at your own end -->
https://onedrive.live.com/?cid=90b44987ff0f70ac&id=90B44987FF0F70AC%21157&authkey=!AOG8D2nRT--ga9I
Now, through Postman I am trying to send requests to the add operation to add new player items - The steps I am following are -->
The error I am receiving is -> 400 Unable to add player object
My sample request body is like so:
{
"player_name":"Didier Drogba",
"player_description":"Brawny, cunning, determined and a heart for attempting the most impossible audacious! The one and only!",
"player_position":"Striker",
"player_age":"42",
"player_club":"Chelsea FC",
"player_":"Hall of Fame",
"player_isactive":"False",
"player_completed":"True"
}
What error did I make? What was the problem? Anythign wrong with the sequence of steps I followed? Can you point out where I went wrong?
Thanks,
EDIT--> The new error is:
<body>
<pre>SyntaxError: Unexpected token F in JSON at position 288
<br> at JSON.parse (<anonymous>)
<br> at parse (E:\REACT\MyProj\backend\node_modules\body-parser\lib\types\json.js:89:19)
<br> at E:\REACT\MyProj\backend\node_modules\body-parser\lib\read.js:121:18
<br> at invokeCallback (E:\REACT\MyProj\backend\node_modules\raw-body\index.js:224:16) .....
Upvotes: 0
Views: 45
Reputation: 983
I have seen your code and there were a couple of changes that were needed.
1) In your player.model.js file, the module.exports should be at the end of the file. This is because you are exporting the player schema even before it is declared and defined.
2) Two properties in the model: a) player_isactive and b) player_completed are defined as Boolean and you were passing a string from the postman. So you need to send the data as follows:
{
"player_name":"Didier Drogba",
"player_description":"Brawny, cunning, determined and a heart for attempting the most impossible audacious! The one and only!",
"player_position":"Striker",
"player_age":"42",
"player_club":"Chelsea FC",
"player_":"Hall of Fame",
"player_isactive": false,
"player_completed":true
}
Kindly make this changes and your problem is solved.
Upvotes: 1