MongoDB tutoria...login
MongoDB tutorial
author:php.cn  update time:2022-04-21 17:49:03

MongoDB delete database


Syntax

The syntax format of MongoDB to delete a 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.

Example

In the following example we deleted the database php.

First, view all databases:

> show dbs
local   0.078GB
php  0.078GB
test    0.078GB

Next we switch to the database php:

> use php
switched to db php
>

Execute the delete command:

> db.dropDatabase()
{ "dropped" : "php", "ok" : 1 }

Finally, we pass Show dbs command database is deleted successfully:

> show dbs
local  0.078GB
test   0.078GB
>

Delete collection

The syntax format of collection deletion is as follows:

db.collection.drop()

php.cn