Creating Data with POST
Свайпніть щоб показати меню
To store data in MongoDB, you create a new document using a model.
This is usually done in a POST route.
app.post('/users', async (req, res) => {
const user = new User(req.body);
const savedUser = await user.save();
res.json(savedUser);
});
The data comes from req.body. A new instance of the model is created and then saved to the database.
After saving, the stored document is returned as a response.
Example request body:
{ "name": "John", "age": 25 }
This creates a new record in the database.
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 1. Розділ 7
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Секція 1. Розділ 7