- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to drop a database in MongoDB?
To drop a database in MongoDB, you need to use dropDatabase() method. The syntax is as follows:
db.dropDatabase()
The above syntax will delete the present working database. If you haven’t selected any database then it will delete the default database.
Before deleting the database, first list all the databases with the help of show command. The query is as follows:
> show dbs;
The following is the output:
admin 0.000GB config 0.000GB local 0.000GB sample 0.000GB
Here, let us delete the database ‘sample’. To delete the database ‘sample’, you need to switch the database with the help of use command. The syntax is as follows:
use yourDatabaseName;
The query is as follows:
> use sample; switched to db sample
Now you can delete the database ‘sample’. To delete the database, you need to use the dropDatabase() method as we discussed above.
The query is as follows:
> db.dropDatabase();
The following is the output:
{ "dropped" : "sample", "ok" : 1 }
Now to check whether the database ‘sample’ is deleted or not, you need to use the show command. The query is as follows:
> show dbs;
The following is the output:
admin 0.000GB config 0.000GB local 0.000GB
Look at the above sample output, there is no ‘sample’ database i.e. we deleted the database successfully.
- Related Articles
- How to drop a database in MongoDB using java?
- How do I drop a MongoDB database from the command line?
- How to drop a collection in MongoDB?
- How to drop a database using JDBC API?
- How to drop a numeric collection from MongoDB?
- How to drop a MongoDB Collection using Java?
- How to drop a table from a database using JDBC API?
- How to clear a MongoDB database?
- Drop all indexes from all the collections in a MongoDB database using the command line?
- How to drop a table from Oracle database using JDBC API?
- How to delete everything in a MongoDB database?
- How to create a new database in MongoDB?
- How to drop an index in MongoDB using Java?
- How to DROP a database in MySQL with character '?' in its name?
- How to create a database in MongoDB using Java?
