MongoDB tutorial : How to drop a database in MongoDB

Introduction :

Drop a database means deleting a database. If you drop a database, it will remove everything inside it.In this tutorial, we will show you how to drop a database in MongoDB.

Drop a database in MongoDB :

Command db.dropDatabase() is used to drop any database if you are currently inside the database. It takes global write lock and blocks all commands until the drop command execution is completed. One thing you should note that it will not delete all users associated with the database. If you want to delete associated users, use dropAllUsersFromDatabase() command.

Example :

  1. Show all databases in the system :
show dbs
  1. Create one new database Users :
use Users
  1. Insert data to the databse first. Else, it will not be visible to the database list :
db.Users.insert({"name" : "Albert"})
  1. Now, show all database list again and use this new database :
show dbs
use Users
  1. Drop this database. Verify that it is actually dropped. :
show dbs

Drop a database in MongoDB

Where is the color and why codevscolor ?

Long story short, I love paintings and I paint on weekends. We(me and my wife) have one Youtube channel. Below is a video that I did recently. If you love this please do subscribe to support us 😊