Delete Database in MongoDB
The db.dropDatabase () command in MongoDB is used to delete an existing database.
DropDatabase () method in MongoDB
The db.dropDatabase () command in MongoDB is used to delete an existing database.
Syntax
The basic syntax of the dropDatabase () command is as follows:
db . dropDatabase ()
This command will delete the selected database. If you do not select any database, it will delete the default test database.
For example
First, check the list of available databases using the show dbs command.
> show dbs local 0.78125GB mydb 0.23012GB test 0.23012GB >
If you want to delete the new database mydb , then the dropDatabase () command will be as follows:
> use mydb switched to db mydb > db . dropDatabase () >{ "dropped" : "mydb" , "ok" : 1 } > Now, try checking the list of databases.
> show dbs local 0.78125GB test 0.23012GB >
According to Tutorialspoint
Previous post: Create Database in MongoDB
Next article: Create Collection in MongoDB
Discover more
Share by
David Pac
Update 25 May 2019
You should read it
- Learn about security features and authentication in MongoDB
- Reference Database in MongoDB
- Compare the performance of MongoDB and SQL Server 2008
- Delete Collection in MongoDB
- Advantages of MongoDB
- The Quiet Details That Make a Sports Betting Platform Feel Reliable
- Instructions on creating toy set images with ChatGPT AI
- How are AI agents changing the journalism industry?
- Create Collection in MongoDB
- Delete Collection in MongoDB
- Data type in MongoDB