Introduction
In this article, we learn MongoDB Drop collection. My main focus describes its simple steps. Drop statement<db.collection.drop()> is used to delete the table and also delete it’s all the data as well from a database. You will delete existing collection in the database.
Prerequisite
You should also read my previous articles. In which I explained. MongoDB sort a document guideline and MongoDB Drop a database.
Implementation Section
- db.collection.drop().
Syntax
The following is a basic syntax-
1 | db.Name _of_collection.drop() |
- <db> is a reserved word.
- <Drop> is also a reserved word used for drop collection.
- <Collection_name> selected collection name which you want to remove.
Example
Drop a collection-:
db.<collection_name>.drop()
Practical work:
First, we find the available list of a collection that exists in a database.
1 2 3 4 5 6 7 | > use logs switched to db logs > show collections programmerhe programmerhelper programmershelper > |
First, we will use command name<show collections> and check the existing database.
1 | Show collections |
Output:
Now we remove collection name like <programmerhelper>.the following query is used to drop a database-
1 | db.programmerhelper.drop() |
Output:
Drop method will return true if it deleted the selected collection.otherwise its return false.you will see both works below a fig.first time I drop <programmershelper> collection its return <true> result. Second time again repeat that work and result give <false>.
Now check again a list of collection.the following command is used-
1 | show collections |
Output:
Conclusion
I wish I could tell you that a great site of MongoDB. You just understands the key element above post-MongoDB Drop collection. You also read my previous lecture. I hope you will understand this lecture. Thank you for reading this lecture. Hope you got the idea. please share it.