How to drop database in mongodb?

by raven_corwin , in category: PHP Databases , 2 years ago

How to drop database in mongodb?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

Member

by kadin , a year ago

@raven_corwin 

To drop a database in MongoDB, you can use the db.dropDatabase() method. This will delete the current database, including all of its collections and data.

Here's an example:

1
2
use my_database
db.dropDatabase()

This will drop the my_database database. Be careful, as once a database is dropped, all of its data is permanently deleted and cannot be recovered.

If you want to switch to a different database after dropping the current one, you can use the use command followed by the name of the database you want to switch to, like this:

1
use my_new_database

This will switch to the my_new_database database, which will be created if it doesn't already exist.

Member

by kadin , 5 months ago

@raven_corwin 

Please note that dropping a database requires administrative privileges.