您可以使用dropDatabase()
函数删除MongoDB数据库中的所有内容。语法如下-
use yourDatabaseName; db.dropDatabase();
上面的语法将删除MongoDB数据库中的所有内容。
要删除MongoDB数据库中的所有内容,让我们首先显示MongoDB中的所有数据库。查询如下-
> show dbs
以下是输出-
use yourDatabaseName; admin 0.000GB config 0.000GB flighInformation 0.000GB local 0.000GB sample 0.000GB sampleDemo 0.000GB test 0.003GB
现在,我们将从数据库“ flightInformation”中删除所有内容。
首先,您需要将数据库切换为“ flightInformation”。查询如下-
> use flighInformation; switched to db flighInformation
现在这是从数据库'flightInformation'中删除所有内容的查询-
> db.dropDatabase();
以下是输出-
{ "dropped" : "flighInformation", "ok" : 1 }
这是列出所有数据库的查询-
> show dbs;
以下是输出-
admin 0.000GB config 0.000GB local 0.000GB sample 0.000GB sampleDemo 0.000GB test 0.003GB
查看示例输出,所有内容均已从数据库“ flightInformation”中删除。