In this part of the Learn Mongo Series, we will learn how to drop a database in mongodb. We will drop the students database.
We can drop a database using the db.dropDatabase() command. Synax is we can select the DB to be dropped using the use <database_name>
command. Now we can drop the database using the db.dropDatabase() command. Let's drop the students database.
show dbs command as shown below :
> show dbs
activityoverload 0.203125GB
animals 0.203125GB
clonecs 0.203125GB
local 0.078125GB
test 0.203125GB
students 0.078125GB
>
>use students
switched to db students
>db.dropDatabase()
{ "dropped" : "students", "ok" : 1 }
>
students DB as shown
below :
> show dbs
activityoverload 0.203125GB
animals 0.203125GB
clonecs 0.203125GB
local 0.078125GB
test 0.203125GB
>
In this part of learn mongo series , we learned about how we can drop a database 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 dbs : This command is used to list all the non-empty mongodb databases on the console. db.dropDatabase() : This command is used to drop the current database.