Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Deleting Data | Section
/
Working with MongoDB in Express Applications

bookDeleting Data

Glissez pour afficher le menu

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.

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 10

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Section 1. Chapitre 10
some-alt