Complete MongoDB Tutorial #20 - Handling POST Requests

preview_player
Показать описание
🐱‍💻 View this course & other premium courses without ads on the Net Ninja Pro site:

🐱‍💻 Access the course files on GitHub:
(lesson code available from lesson 15 onwards)

🐱‍💻 Modern JavaScript Course:

Рекомендации по теме
Комментарии
Автор

Hi shuan looks like the video number in title is wrong it should be 20. Thanks for all the videos

dandendrasingh
Автор

Here's the raw JSON (the one posted below didn't work for me for some reason):
{
"title": "The Final Empire",
"author": "Brandon Sanderson",
"rating": 9,
"pages": 420,
"genres": ["fantasy", "magic"],
"reviews": [
{ "name": "Shaun", "body": "Couldn't put this book down."},
{ "name": "Chun-li", "body": "Love it."}
]
}

ubarjaktarev
Автор

Thanks for the great tutorial.
If anyone faced the problem that when making a post request it just makes a new document with only the id, this is because in postman you need to change (body > raw) from text into json

BenNouba
Автор

I like to use async await:
exports.postBook = async (req, res) => {
const newBook = req.body;
let db = getDb();
try {
const result = await

} catch (error) {
res.status(500).json({ msg: 'Could not post new object.' });
}
};

alexpiano
Автор

your way of teaching is awesome, love from PAKISTAN ❤️❤️❤️

jawadshaikh
Автор

4:14
{
 "title": "The Final Empire",
"author": "Brandon Sanderson",
"ratinig": 9,
"pages": 420,
"genres": [
"fantasy",
"magic"
],
"reviews": [
{
"name": "Shaun",
"body": "Couldn't put this book down."
},
{
"name": "Chun-Li",
"body": "Love it."
}
]
},

Mong-Yun_Chen_
Автор

@The Net Ninja Great stuff. The course lesson should be Tutorial #20 but it says #10. Thank you :D.

darkmojojojo
Автор

Please also include mongodb aggregation framework with mongooses or mongodb driver (filtering and sorting sub document arrays) geojson. It would be very helpful 🙏🙏

okeyshourovroy
Автор

what about using docker? how can we configure that?

aldotugasumb
Автор

If anyone is having trouble with the post request failing, I have a possible solution.

If your request body is not being received, it is most likely because newer versions of Express don't include the body parser automatically. To test if it is the body is the problem, you can console log the req.body to see if it comes up as null in the terminal upon request.

Take the following steps to correct:

- Stop your server and Install the body parser - npm install body-parser
- Import the body parser at the top of the file - const bodyParser = require('body-parser');
- Enable the body parser for the app, just below the declaration of the app - app.use(bodyParser.json());
- Retry your request and the body parser should convert the Json and solve the problem

This resolved the issue for me.

mathewdavies
Автор

I only add the new _id-s to the books collection without the data 😖

waxinggibbons
Автор

amazing tutorial man! you have a typo in ur title, it says this is tutorial #10

stephanodev
Автор

I am facing a problem in post request...When I add data using post query, for some reason the query keeps on processing infinitely...I am using async as well but still the problem remains the same (I am using thunderclient vscode extension for requests)....Please help!

apxmvrc
Автор

{
"title": "The Final Empire",
"author": "Brandon Sanderson",
"rating": 9,
"pages": 420,
"genres": [
"fantasy",
"magic"
],
"reviews": [
{
"name": "Shaun",
"body": "Couldn't put this book down."
},
{
"name": "Chun-Li",
"body": "Love it."
}
]
}

gryp
Автор

Hello Shaun, I've been trying to reach you on all platforms, I just paid for the Modern JavaScript on your website, I've having trouble downloading the videos to my pc. Is there a way you can help? Thanks

tundejoseph
Автор

it hurts so much to start your video with "alright then" without saying "gang"

mahmoudakrm
visit shbcf.ru