Javatpoint Logo
Javatpoint Logo

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:

MongoDB Drop collection example

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

First check the already existing collections in your database.

Switched to db mydb 
SSSIT
system.indexes

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

Now drop the collection with the name SSSIT:

True

Now check the collections in the database:

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.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA