How to drop all databases in mongodb?

by elisha_langworth , in category: MySQL , 22 days ago

How to drop all databases in mongodb?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by lily , 21 days ago

@elisha_langworth 

To drop all databases in MongoDB, you will need to run the following command in the MongoDB shell:

1
2
use admin
db.adminCommand( { "listDatabases": 1 } ).databases.forEach(function(d){db.getSiblingDB(d.name).dropDatabase()})


This command will switch to the admin database, list all databases, and then iterate through each database to drop them one by one. Make sure you have the necessary privileges to run this command as it will delete all data in all databases.