MongoDB delete database and delete collection

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:
  1. > show dbs
  2. local 0.000GB
  3. students 0.000GB
  4. test 0.000GB
Next we switch to the database students:
  1. > use students
  2. switched to db students
Execute the delete command:
  1. > db.dropDatabase()
  2. { "dropped" : "students", "ok" : 1 }
Finally, we pass the show dbs command whether the database is deleted successfully:
  1. > show dbs
  2. local 0.000GB
  3. 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:
  1. > show dbs
  2. local 0.000GB
  3. runoob 0.000GB
  4. students 0.000GB
  5. test 0.000GB
  6. > use runoob
  7. switched to db runoob
  8. > show tables
  9. runoobtable
  10. > db.runoobtable.drop()
  11. true
  12. > show dbs
  13. local 0.000GB
  14. students 0.000GB
  15. test 0.000GB

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327073808&siteId=291194637