Skip to main content
TopMiniSite

Back to all posts

How to Drop All Databases In Mongodb?

Published on
3 min read
How to Drop All Databases In Mongodb? image

Best Database Management Tools to Buy in January 2026

1 Concepts of Database Management

Concepts of Database Management

BUY & SAVE
$31.96 $193.95
Save 84%
Concepts of Database Management
2 Database Systems: Design, Implementation, & Management

Database Systems: Design, Implementation, & Management

BUY & SAVE
$10.86
Database Systems: Design, Implementation, & Management
3 Concepts of Database Management (MindTap Course List)

Concepts of Database Management (MindTap Course List)

BUY & SAVE
$70.00 $193.95
Save 64%
Concepts of Database Management (MindTap Course List)
4 Database Systems: Design, Implementation, & Management

Database Systems: Design, Implementation, & Management

BUY & SAVE
$86.49
Database Systems: Design, Implementation, & Management
5 Corel WordPerfect Office Professional 2021 | Office Suite of Word Processor, Spreadsheets, Presentation & Database Management Software [PC Disc]

Corel WordPerfect Office Professional 2021 | Office Suite of Word Processor, Spreadsheets, Presentation & Database Management Software [PC Disc]

  • ALL-IN-ONE SUITE: WORD, SPREADSHEETS, PRESENTATIONS & MORE!
  • SUPPORTS 60+ FORMATS, ENSURING SEAMLESS FILE SHARING & EDITING.
  • BUILT-IN LEGAL TOOLS STREAMLINE DOCUMENT CREATION & FORMATTING.
BUY & SAVE
$237.99
Corel WordPerfect Office Professional 2021 | Office Suite of Word Processor, Spreadsheets, Presentation & Database Management Software [PC Disc]
6 Corel WordPerfect Office Professional 2021 | Office Suite of Word Processor, Spreadsheets, Presentation & Database Management Software [PC Download]

Corel WordPerfect Office Professional 2021 | Office Suite of Word Processor, Spreadsheets, Presentation & Database Management Software [PC Download]

  • ALL-IN-ONE OFFICE SUITE FOR SEAMLESS DOCUMENT CREATION AND MANAGEMENT.
  • SUPPORTS 60+ FILE FORMATS FOR EASY EDITING AND SHARING OF DOCUMENTS.
  • BUILT-IN LEGAL TOOLS STREAMLINE DOCUMENT PREPARATION FOR PROFESSIONALS.
BUY & SAVE
$399.99
Corel WordPerfect Office Professional 2021 | Office Suite of Word Processor, Spreadsheets, Presentation & Database Management Software [PC Download]
7 Data Mining: Practical Machine Learning Tools and Techniques (Morgan Kaufmann Series in Data Management Systems)

Data Mining: Practical Machine Learning Tools and Techniques (Morgan Kaufmann Series in Data Management Systems)

  • EXCLUSIVE 'NEW' LABEL ATTRACTS EAGER CONSUMERS' ATTENTION!
  • ENHANCED FEATURES BOOST PERFORMANCE AND CUSTOMER SATISFACTION.
  • LIMITED-TIME 'NEW' OFFERS CREATE URGENCY FOR IMMEDIATE PURCHASES!
BUY & SAVE
$54.99 $69.95
Save 21%
Data Mining: Practical Machine Learning Tools and Techniques (Morgan Kaufmann Series in Data Management Systems)
8 The Manga Guide to Databases

The Manga Guide to Databases

BUY & SAVE
$19.96 $24.99
Save 20%
The Manga Guide to Databases
+
ONE MORE?

To drop all databases in MongoDB, you can use the following command:

use admin db.adminCommand({ listDatabases: 1 }).databases.forEach(function (d) { if (d.name !== 'admin' && d.name !== 'local' && d.name !== 'config') { db.getSiblingDB(d.name).dropDatabase(); } });

This script will first switch to the admin database, fetch a list of databases using the listDatabases command, and then iterate through each database apart from the built-in ones like admin, local, and config to drop them one by one. By running this script, you can effectively drop all user-created databases in MongoDB.

How to drop all databases in MongoDB using a GUI tool?

To drop all databases in MongoDB using a GUI tool, you can use a tool like MongoDB Compass. Here's how you can do it:

  1. Open MongoDB Compass and connect to your MongoDB server.
  2. Once connected, click on the "Databases" tab on the left-hand side to view all the databases in your MongoDB server.
  3. Right-click on each database one by one and select the "Drop Database" option. Confirm the action when prompted.
  4. Repeat this process for each database until all databases have been dropped.

Please note that dropping all databases will permanently delete all data in your MongoDB server, so be sure to back up any important data before proceeding with this action.

How to drop all databases in MongoDB with confirmation prompt?

To drop all databases in MongoDB with a confirmation prompt, you can use the following steps:

  1. Connect to your MongoDB instance using the mongo shell or a GUI tool such as MongoDB Compass.
  2. Run the following command to list all the databases:

show dbs

  1. Make sure you are in the correct database and then run the following command to drop all databases:

db.getMongo().getDBNames().forEach(function(database){ if(database != 'admin' && database != 'local' && database != 'config'){ print('Dropping database: ' + database); db.getSiblingDB(database).dropDatabase(); } });

  1. This command will drop all databases except for the system databases like 'admin', 'local', and 'config'.
  2. The command will prompt you for confirmation before dropping each database. Make sure to carefully review the output and confirm the drop for each database.
  3. Once you have confirmed the drop for each database, all databases except for the system databases will be dropped.

Please make sure to backup any important data before dropping all databases, as this operation cannot be undone.

How to drop all databases in MongoDB using Studio 3T?

To drop all databases in MongoDB using Studio 3T, follow these steps:

  1. Connect to your MongoDB server in Studio 3T.
  2. In the Connection Tree on the left-hand side, right-click on the server connection and choose the "Open Shell" option.
  3. In the Shell tab that appears, run the following command to list all databases:

show dbs

  1. Identify the databases you want to drop and note down their names.
  2. Now, run the following command to drop a database in MongoDB:

use db.dropDatabase()

Replace <databaseName> with the name of the database you want to drop. Repeat this command for each database you want to drop. 6. After dropping all the databases you want to delete, run the "show dbs" command once more to verify that all databases have been dropped.

Please note that dropping databases is a destructive operation and cannot be undone. Make sure to backup any important data before proceeding with these steps.