BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Drop Database in MongoDB

Last Updated: September 16, 2017 by Chaitanya Singh | Filed Under: MongoDB Tutorial

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
beginnersbook  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 “beginnersbook”.

> use beginnersbook
switched to db beginnersbook

Note: Change the database name in the above command, from beginnersbook to the database that needs to be deleted.

3. Now, the currently selected database is beginnersbook so the command db.dropDatabase() would delete this database.

> db.dropDatabase()
{ "dropped" : "beginnersbook", "ok" : 1 }

The command executed successfully and showing the operation “dropped” and status “ok” which means that the database is dropped.
MongoDB drop database

4. To verify that the database is deleted successfully. Execute the show dbs command again to see the list of databases after deletion.
Verifying that database is dropped
As you can see that the database “beginnersbook” is not present in the list that means it has been dropped successfully.

❮ PreviousNext ❯

Top Related Articles:

  1. Introduction to MongoDB
  2. MongoDB Tutorial for Beginners
  3. Introduction to NoSQL Databases
  4. Create Database in MongoDB
  5. Create Collection in MongoDB

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

MongoDB Tutorial

  • MongoDB Tutorial
  • NoSQL Introduction
  • Introduction to MongoDB
  • Mapping Relational Database to MongoDB
  • Install MongoDB
  • Create Database
  • Drop Database
  • Create Collection
  • Drop Collection
  • Insert Document
  • Query Document
  • Update Document
  • Delete Document
  • MongoDB Projection
  • MongoDB limit() and skip()
  • MongoDB sorting
  • MongoDB Indexing

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap