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.

Post Graduate Program In Data Science

The Ultimate Ticket To Top Data Science Job RolesExplore Course
Post Graduate Program In Data Science

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

Free Course: Introduction to Data Science

Learn the Fundamentals of Data ScienceEnroll Now
Free Course: Introduction to Data Science

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!

Learn over a dozen of data science tools and skills with PG Program in Data Science and get access to masterclasses by Purdue faculty. Enroll now and add a shining star to your data science resume!

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 PGP Data Science Certification Bootcamp Program. Do check it out!

About the Author

SimplilearnSimplilearn

Simplilearn is one of the world’s leading providers of online training for Digital Marketing, Cloud Computing, Project Management, Data Science, IT, Software Development, and many other emerging technologies.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.