MongoDB Drop Database

📘 Premium Read: Access my best content on Medium member-only articles — deep dives into Java, Spring Boot, Microservices, backend architecture, interview preparation, career advice, and industry-standard best practices.

✅ Some premium posts are free to read — no account needed. Follow me on Medium to stay updated and support my writing.

🎓 Top 10 Udemy Courses (Huge Discount): Explore My Udemy Courses — Learn through real-time, project-based development.

▶️ Subscribe to My YouTube Channel (172K+ subscribers): Java Guides on YouTube

In this post, we will see how to drop a database using the MongoDB command.

The dropDatabase() Method

MongoDB db.dropDatabase() command is used to drop a existing database.

Syntax

The basic syntax of dropDatabase() command is as follows −
db.dropDatabase()
This will delete the selected database. If you have not selected any database, then it will delete the default 'test' database.

Example

First, check the list of available databases by using the command, show dbs.
> show dbs;
admin   0.000GB
config  0.000GB
local   0.000GB
Let's first create a new database with the following command:
> use mydb
switched to db mydb
Now, let's drop this database with dropDatabase() command:
> db.dropDatabase()
{ "dropped" : "mydb", "ok" : 1 }
Now let's use dbs command to show all databases:
> show dbs;
admin   0.000GB
config  0.000GB
local   0.000GB

Summary

The below diagram shows the summary of all the commands used in this post:

Comments

Spring Boot 3 Paid Course Published for Free
on my Java Guides YouTube Channel

Subscribe to my YouTube Channel (165K+ subscribers):
Java Guides Channel

Top 10 My Udemy Courses with Huge Discount:
Udemy Courses - Ramesh Fadatare