Delete Collection in MongoDB

The db.collection.drop () method in MongoDB is used to delete a Collection from the database.

Drop () method in MongoDB

The db.collection.drop () method in MongoDB is used to delete a Collection from the database.

Syntax

The basic syntax of the drop () command is as follows:

 db . COLLECTION_NAME . drop () 

For example

First, you check the available Collections within the mydb database.

 > use mydb switched to db mydb > show collections mycol mycollection system . indexes tutorialspoint > 

Now, delete the Collection as mycollection as follows:

 > db . mycollection . drop () true > 

Then, check the Collection again inside the database:

 > show collections mycol system . indexes tutorialspoint > 

The drop () method will return true, if the selected Collection is successfully deleted, otherwise, it will return false.

According to Tutorialspoint

Previous post: Create Collection in MongoDB

Next lesson: Data type in MongoDB

4 ★ | 2 Vote