3.10. MongoDB deletes the database

发布时间 :2025-10-25 12:32:56 UTC      

3.10.1. Grammar

The syntax format for 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.

3.10.2. Example

For the following example, we deleted the database runoob.

First, look at all the databases:

> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
runoob  0.000GB

Next, we switch to the database runoob:

> use runoob
switched to db runoob
>

Execute the delete command:

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

Finally, we use show dbs to command whether the database has been deleted successfully:

> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB

3.10.3. Delete a collection

The collection deletion syntax is in the following format:

db.collection.drop()

The following example deletes the collection site in the runoob database:

> use runoob
switched to db runoob
> db.createCollection("runoob")     # 先创建集合,类似数据库中的表
> show tables             # show collections 命令会更加准确点
runoob
> db.runoob.drop()
true
> show tables
>
Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.