In this part of the Learn Mongo Series, we will learn how to drop a collection in mongodb. We will drop the details collection from the database.
We can drop a collection using the db.collection.drop() command. The syntax is db.<Collection_name>.drop() . Let's start dropping
collections.
show collections command as shown below :
>use students
switched to db students
> show collections
name
roll
details
rollNumber
system.indexes
>
db.collection.drop() command. We are deleting the
details collection from students db as shown below :
>db.details.drop()
true
>
details collection as shown
below :
> show collections
name
roll
rollNumber
system.indexes
>
In this part of learn mongo series , we learned about how we can drop a collection in mongodb. We learned the following commands of mongodb :
use : This command is use to either create a new database or switch to an already existing database. show collections : This command is used to list all the collections available in the mongodb databases on the console. db.<Collection_name>.drop() : This command is used to drop the collection.