How to drop database in mongodb?

by raven_corwin , in category: PHP Databases , a year ago

How to drop database in mongodb?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer


by kadin , 9 months ago


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:

use my_database

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:

use my_new_database

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