MongoDB Delete Database

MongoDB Delete Database – In this MongoDB Tutorial, we shall learn to drop or delete a MongoDB Database.

To delete or drop a database from MongoDB, follow the below steps :

  1. Select the database you want to delete with the help of USE <database> command.
    Following is the syntax of USE command :
    use <database_name>
  2. Drop the database with the help of db.dropDatabase() command.
    Following is the syntax of USE command :
    db.dropDatabase()

 

Example to drop MongoDB

Following is an example where we shall try deleting database named tutorialkart.

Refer MongoDB Create Database, if you have not already created one.

Open Mongo Shell and follow the commands in sequence.

Following is the explanation for each mongodb command we executed above

  1. show dbs  there are three databases. We shall delete tutorialkart database in this demonstration.
  2. use tutorialkart  switched to tutorialkart database.
  3. db.dropDatabase()  drops the database that is currently in use i.e., tutorialkart database.
  4. show dbs  now there are only two databases, because tutorialkart database is no more present.