Drop Database in MongoDB - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
Drop Database in MongoDB

Drop Database in MongoDB

Drop Database in MongoDB

In the last tutorial we learned how to create a database in MongoDB. Here we will see how to drop a database in MongoDB. We use db.dropDatabase() command to delete a database. You should be very careful when deleting a database as this will remove all the data inside that database, including collections and documents stored in the database.

MongoDB Drop Database

The syntax to drop a Database is:
db.dropDatabase()
We do not specify any database name in this command, because this command deletes the currently selected database. Lets see the steps to drop a database in MongoDB.
1. See the list of databases using show dbs command.
> show dbs
admin
0.000GB
mycareerrepublic
0.000GB
local 0.000GB
It is showing two default databases and one database “beginnersbook” that I have created.
2. Switch to the database that needs to be dropped by typing this command.
use database_name
For example I want to delete the database “mycareerrepublic”.
> use mycareerrepublic
switched to db mycareerrepublic
Note: Change the database name in the above command, from mycareerrepublic to the database that needs to be deleted.
3. Now, the currently selected database is mycareerrepublic so the command db.dropDatabase() would delete this database.
> db.dropDatabase()
{ "dropped" : "mycareerrepublic", "ok" : 1 }
The command executed successfully and showing the operation “dropped” and status “ok” which means that the database is dropped.
4. To verify that the database is deleted successfully. Execute the show dbs command again to see the list of databases after deletion.

As you can see that the database “mycareerrepublic” is not present in the list that means it has been dropped successfully.

About Mariano

I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

0 comments:

Featured post

Political Full Forms List

Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

Powered by Blogger.