mongodb drop database
www.igiftidea.com
To drop a database in MongoDB, you can use the dropDatabase()
method. Here are the steps to drop a database in MongoDB:
Open the MongoDB shell: Open a terminal or command prompt and run the
mongo
command to open the MongoDB shell.Switch to the database you want to drop: Use the
use
command followed by the name of the database to switch to the database you want to drop. For example, to switch to a database named "mydb", run the following command:
use mydb
- Drop the database: Run the
dropDatabase()
method to drop the database. For example, to drop the "mydb" database, run the following command:
db.dropDatabase()
- Confirm the database has been dropped: MongoDB will return a message indicating that the database has been dropped. You can also check for the existence of the database by running the
show dbs
command.
Note that dropping a database will permanently delete all data stored in that database. Make sure to back up any important data before dropping a database.