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.

Become a Data Scientist with Hands-on Training!

Data Scientist Master’s ProgramExplore Program
Become a Data Scientist with Hands-on Training!

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

Become a Data Scientist with Hands-on Training!

Data Scientist Master’s ProgramExplore Program
Become a Data Scientist with Hands-on Training!

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
Caltech Post Graduate Program in Data Science

Cohort Starts: 2 Apr, 2024

11 Months$ 4,500
Post Graduate Program in Data Science

Cohort Starts: 15 Apr, 2024

11 Months$ 4,199
Post Graduate Program in Data Analytics

Cohort Starts: 15 Apr, 2024

8 Months$ 3,749
Applied AI & Data Science

Cohort Starts: 16 Apr, 2024

3 Months$ 2,624
Data Analytics Bootcamp

Cohort Starts: 24 Jun, 2024

6 Months$ 8,500
Data Scientist11 Months$ 1,449
Data Analyst11 Months$ 1,449