Reading Data with GET
Свайпніть щоб показати меню
To retrieve data from MongoDB, you use methods provided by the model.
To get all documents:
app.get('/users', async (req, res) => {
const users = await User.find();
res.json(users);
});
To get a single document by id:
app.get('/users/:id', async (req, res) => {
const user = await User.findById(req.params.id);
res.json(user);
});
Examples:
'/users': returns all users;'/users/123': returns user with id 123.
These methods allow your API to read data from the database and return it to the client.
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 1. Розділ 8
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Секція 1. Розділ 8