A MongoDB delete database
1. The syntax format of MongoDB delete database is as follows:
db.dropDatabase()
Delete the current database, the default is test, you can use the db command to view the current database name.
2. Examples
The following example we delete the database
students
.
First, look at all databases:
> show dbs
local 0.000GB
students 0.000GB
test 0.000GB
Next we switch to the database students:
> use students
switched to db students
Execute the delete command:
> db.dropDatabase()
{ "dropped" : "students", "ok" : 1 }
Finally, we pass the show dbs command whether the database is deleted successfully:
> show dbs
local 0.000GB
test 0.000GB
Two delete sets
1. The syntax format of collection deletion is as follows:
db.collection.drop()
2. Examples
The following example deletes the collection runoobtable in the runoob database:
> show dbs
local 0.000GB
runoob 0.000GB
students 0.000GB
test 0.000GB
> use runoob
switched to db runoob
> show tables
runoobtable
> db.runoobtable.drop()
true
> show dbs
local 0.000GB
students 0.000GB
test 0.000GB