How to remove documents using Node.js Mongoose?

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.