Deleting Data
Desliza para mostrar el menú
To remove data from MongoDB, you use methods provided by the model.
A common method is findByIdAndDelete.
app.delete('/users/:id', async (req, res) => {
await User.findByIdAndDelete(req.params.id);
res.send('user deleted');
});
The id is taken from the route parameter, and the matching document is removed from the database.
Example:
DELETE '/users/123': deletes user with id 123.
This allows your API to remove data when it is no longer needed.
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 1. Capítulo 10
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Sección 1. Capítulo 10