Categories
JavaScript Answers

How to drop a database with Mongoose and JavaScript?

Spread the love

To drop a database with Mongoose and JavaScript, we use the Mongo native driver’s drop method.

For instance, we write

mongoose.connection.collections["collectionName"].drop((err) => {
  console.log("collection dropped");
});

to get the Mongo collection with collections.

And we call drop with a callback that’s called when there’s an error to drop the collectionName 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 *