“Mongoose remove” Respostas de código

Excluir mangusto

// Delete a user by username
app.delete('/users/:Username', (req, res) => {
  Users.findOneAndRemove({ Username: req.params.Username })
    .then((user) => {
      if (!user) {
        res.status(400).send(req.params.Username + ' was not found');
      } else {
        res.status(200).send(req.params.Username + ' was deleted.');
      }
    })
    .catch((err) => {
      console.error(err);
      res.status(500).send('Error: ' + err);
    });
});
Quaint Quelea

Mongoose encontre e exclua

Campground.findByIdAndRemove(req.params.id, function(err){
      if(err){
          res.redirect("/campgrounds");
      } else {
          res.redirect("/campgrounds");
      }
   });
Mocat

Propriedade de Excluir Mongoose

User.collection.update({_id: user._id}, {$unset: {field: 1 }});
florinrelea

Exclua o documento Mongoose

Tank.deleteOne({ size: 'large' }, function (err) {
  if (err) return handleError(err);
  // deleted at most one tank document
});
KubernetesDan

Mongoose Remova dados

Remove is deprecated - use delete
Update for Mongoose v5.5.3 - remove() is now deprecated.
Use deleteOne(), deleteMany() or findOneAndDelete() instead.
florinrelea

Mongoose remove

const res = await Character.remove({ name: 'Eddard Stark' });
res.deletedCount; // Number of documents removed
Abdulhakim Zeinu

Respostas semelhantes a “Mongoose remove”

Perguntas semelhantes a “Mongoose remove”

Mais respostas relacionadas para “Mongoose remove” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código