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
5 ★ | 1 Vote
You should read it
- Create Database in MongoDB
- MongoDB malicious code attacks more than 26,000 victims in a week
- 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
- Delete Document in MongoDB
- Index (Mong) in MongoDB
- Overview of MongoDB
- MongoDB queries and tasks you should know
- Create Backup in MongoDB