MongoDB Drop collection-Programmershelper

0
188
Spread the love

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-

  • <db> is a reserved word.
  • <Drop> is also 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.

First, we will use command name<show collections> and check the existing database.

Output:

Alt tag MongoDB drop collection

Now we remove collection name like <programmerhelper>.the following query is used to drop a database-

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>.

Alt tag MongoDB Drop collection

Now check again a list of collection.the following command is used-

Output:

Alt Tag MongoDB drop collection

Conclusion

I wish I could tell you that a great site of MongoDB.you just understands 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.