MongoDB Database Deletion Using MongoShell (original) (raw)

Last Updated : 5 May, 2026

MongoDB organizes data into databases, collections, and documents with a flexible, schema-flexible model.

Database in MongoDB

A MongoDB database groups collections that store documents and can host multiple databases on one server.

Collection in MongoDB

A collection groups related documents in MongoDB without enforcing a fixed schema.

[
{
"Name": "Alen",
"Age": 24,
"Gender": "Male"
},
{
"Name": "Kim",
"Age": 32,
"Gender": "Male"
},
{
"Name": "Lee",
"Age": 21,
"Gender": "Female"
}
]

Document in MongoDB

A document is MongoDB’s basic data unit, stored as field–value pairs with flexible structure.

{
"Name": "Adam",
"Age": 24,
"Gender": "Male"
}

MongoDB Shell (mongosh)

MongoDB Shell (mongosh) is a command-line JavaScript interface for managing and querying MongoDB.

Deleting a Database in MongoDB

Deleting a database in MongoDB is a straightforward process using the db.dropDatabase() command. This command permanently removes the currently selected database along with all its collections and documents.

**Syntax

db.dropDatabase()

**Example 1: To delete the userDB database, first select it using the use userDB command.

**Query:

// Step 1: Select the database to delete
use userDB

// Step 2: Drop the selected database
db.dropDatabase()

**Output:

This confirms that the database userDB has been deleted.

**Example 2: Delete a Database that is not currently selected (by switching to it first).

Follow these steps:

**1. Check the Current Database:

db

This command returns the name of the currently selected database.

**2. List All Databases:

show dbs

This command lists all the available databases on the MongoDB server.

**3. Select the Database to Delete:

use adminDB

Replace adminDB with the name of the database you want to delete.

**4. Delete the Selected Database:

db.dropDatabase()

This confirms that the adminDB database has been deleted successfully.

Important Points to Remember

Here are some important points to be remembered: