MongoDB is a database management system with the following features:

  • NoSQL: MongoDB is a document-based database that employs NoSQL (not only SQL). Each document is a key with a complicated value. Multiple key-value pairs can be found in the document value.
  • Free: You do not have to pay anything to use it in your application.
  • Cross-Platform: MongoDB, built on one platform (say, Linux), operates on other systems (Windows, macOS, and so on) without requiring any code changes.
  • Open Source: MongoDB database program is open-source, and the open source community contributes to its development.
  • Document Oriented: MongoDB is document-oriented, storing records as JSON documents. There are numerous benefits to doing so. One significant benefit is that adding new features to the database (columns in a relational database) is simple.

In this article, we will be learning how to drop a database in MongoDB.

Take Your Data Scientist Skills to the Next Level

With the Data Scientist Master’s Program from IBMExplore Program
Take Your Data Scientist Skills to the Next Level

Steps to Drop Database in MongoDB

In order to drop a database or delete a database in MongoDB, the following steps are followed:

Step 1

List out all the available databases by using the show dbs command.

Syntax

show dbs

Step 2

Select and connect to the database which is to be deleted using the use command in the MongoDB shell.

Syntax

use <database_name>

Step 3

Drop the connected database using the dropDatabase() function.

Syntax

db.dropDatabase()

Step 4

Check the list of databases again now using the show command to confirm the deletion of the database.

Syntax

show dbs

Let us now illustrate this process of dropping a MongoDB database through the implementation of an example.

Example – Drop MongoDB Database

Let us consider that we need to drop the database named db1. We execute the steps mentioned above to perform this operation.

Step 1

Listing out all databases.

>show dbs

oldDB       0.87513GB

testDB      0.76524GB

db1           0.34281GB

The database that we need to drop exists, so let us go forward with the next step.

Step 2

Select the required database db1.

>use db1

switched to db db1

Take Your Data Scientist Skills to the Next Level

With the Data Scientist Master’s Program from IBMExplore Program
Take Your Data Scientist Skills to the Next Level

Step 3

Now that this database is connected, drop or delete it.

>db.dropDatabase()

{ "dropped" : "db1", "ok" : 1 }

Step 4

Confirm the deletion of the database.

>show dbs

oldDB       0.87513GB

testDB      0.76524GB

We see that the database does not exist anymore.

All the above steps have been summarized in the following code snippet:

>show dbs

oldDB       0.87513GB

testDB      0.76524GB

db1           0.34281GB

>use db1

switched to db db1

>db.dropDatabase()

{ "dropped" : "db1", "ok" : 1 }

>show dbs

oldDB       0.87513GB

testDB      0.76524GB

>

Thus, the database will be successfully deleted. Congratulations on the achievement!

Build Your Data Science Career With Simplilearn

MongoDB is a NoSQL, free, cross-platform, open-sourced database that can store any kind of data and not just in rows and tables. In this article, we learned how to quickly drop a database in MongoDB using the dropDatabase() function in MongoDB.

In order to build a successful career in the field of data science, one must learn MongoDB as well thoroughly to create, manipulate, delete and update data and perform different operations. Prefer to take a comprehensive bootcamp program that fits all your needs to level up your career? Well, you are in the right place as Simplilearn offers the best in the industry courses to take a leap in your data science career through its PG in Data Science. Do check it out!

Data Science & Business Analytics Courses Duration and Fees

Data Science & Business Analytics programs typically range from a few weeks to several months, with fees varying based on program and institution.

Program NameDurationFees
Professional Certificate Program in Data Engineering

Cohort Starts: 2 Jan, 2025

7 months$ 3,850
Professional Certificate in Data Science and Generative AI

Cohort Starts: 6 Jan, 2025

6 months$ 3,800
Post Graduate Program in Data Analytics

Cohort Starts: 13 Jan, 2025

8 months$ 3,500
Caltech Post Graduate Program in Data Science

Cohort Starts: 13 Jan, 2025

11 months$ 4,000
Professional Certificate in Data Analytics and Generative AI

Cohort Starts: 13 Jan, 2025

22 weeks$ 4,000
Data Scientist11 months$ 1,449
Data Analyst11 months$ 1,449