Drop Database

db.dropDatabase() method is used to drop the database.

Note:- When you drop the database then all collections and documents will be deleted off from this database.

Syntax:-


use databaseName
> db.dropDatabase()

Example:- Firstly check all database


show dbs

Output:-

employee_management
school_management

Now delete the database


use employee_management
> db.dropDatabase()

Now check the database


show dbs

Output:-

school_management

Drop Database – Interview Questions

Q 1: How do you delete a database in MongoDB?

Ans: Use db.dropDatabase().

Q 2: What does dropDatabase() return?

Ans: It returns an object showing success status.

Q 3: Do you need to select the database before dropping?

Ans: Yes, you must select the database using use.

Q 4: Can dropped databases be recovered?

Ans: No, unless backup is available.

Q 5: Is dropping database permanent?

Ans: Yes, it permanently deletes all data.

Related Drop Database Topics