Categories
JavaScript Answers

How to remove documents using Node.js Mongoose?

Spread the love

Sometimes, we want to remove documents using Node.js Mongoose.

In this article, we’ll look at how to remove documents using Node.js Mongoose.

How to remove documents using Node.js Mongoose?

To remove documents using Node.js Mongoose, we can use the deleteOne or deleteMany method.

For instance, we write

TeleBot.deleteMany({
  chatID
}, (err, _) => {
  if (err) {
    return console.log(err);
  }
});

to call deleteMany to delete all entries with chatId equals chatId`.

The callback is run when deleteMany is done.

When there’re errors, err is set.

Conclusion

To remove documents using Node.js Mongoose, we can use the deleteOne or deleteMany method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *