mongodbHow to drop a database in MongoDB?
To drop a database in MongoDB, use the dropDatabase()
method. This method will delete the current database.
Example
use myDatabase
db.dropDatabase()
Output example
{ "dropped" : "myDatabase", "ok" : 1 }
The dropDatabase()
method takes no arguments and returns a document with the field dropped
containing the name of the database that was dropped.
Code explanation
use myDatabase
: This command is used to switch to the database that you want to drop.db.dropDatabase()
: This command is used to drop the current database.
Helpful links
More of Mongodb
- How to use hint in MongoDB?
- How to bind IP addresses for MongoDB server?
- How to use watch in MongoDB?
- How to query with "not equal" condition in MongoDB?
- How to kill an operation in MongoDB?
- How to specify a password for MongoDB Docker?
- How to use MongoDB HTTP interface?
- How to filter by date in MongoDB?
- How to use unwind in MongoDB?
- How to remove a field from MongoDB?
See more codes...