TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

MongoDB Drop Collection

MongoDB Drop Collection for beginners and professionals with examples on CRUD, insert document, query document, update document, delete document, use database, projection etc.

<< Back to MONGODB

MongoDB Drop collection

In MongoDB, db.collection.drop() method is used to drop a collection from a database. It completely removes a collection from the database and does not leave any indexes associated with the dropped collections.

The db.collection.drop() method does not take any argument and produce an error when it is called with an argument. This method removes all the indexes associated with the dropped collection.

Syntax:

db.COLLECTION_NAME.drop()

MongoDB Drop collection example

Let's take an example to drop collection in MongoDB.

First check the already existing collections in your database.

>use mydb
Switched to db mydb 
> show collections
SSSIT
system.indexes

Note: Here we have a collection named SSSIT in our database.

Now drop the collection with the name SSSIT:

>db.SSSIT.drop()
True

Now check the collections in the database:

>show collections
System.indexes

Now, there are no existing collections in your database.

Note: The drop command returns true if it successfully drops a collection. It returns false when there is no existing collection to drop.





Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf