Categories
JavaScript Answers

How to drop a database with Mongoose?

Spread the love

Sometimes, we want to drop a database with Mongoose.

In this article, we’ll look at how to drop a database with Mongoose.

How to drop a database with Mongoose?

To drop a database with Mongoose, we can remove all the content of a collection.

For instance, we write

Model.remove({}, (err) => {
  console.log('collection removed')
});

to call Model.remove with an empty object to remove all items in the collection that’s mapped to Model.

The callback is run when all the items are removed from the collection.

Conclusion

To drop a database with Mongoose, we can remove all the content of a collection.

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 *