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
You've just finished reading the article "Delete Collection in MongoDB" edited by the TipsMake team. You can save delete-collection-in-mongodb.pdf to your computer here to read later or print it out. We hope this article has provided you with many useful tech tips and tricks. You can search for similar articles on tips and guides. Thank you for reading and for following us regularly.