3.9. MongoDB creates a database

发布时间 :2025-10-25 12:33:01 UTC      

3.9.1. Grammar

The syntax format for MongoDB to create a database is as follows:

use DATABASE_NAME

If the database does not exist, create the database, otherwise switch to the specified database.

3.9.2. Example

For the following example, we created the database runoob:

> use runoob
switched to db runoob
> db
runoob
>

If you want to view all databases, you can use the show dbs Command:

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

As you can see, the database we just created, runoob, is not in the database list. To display it, we need to insert some data into the runoob database.

> db.runoob.insert({"name":"菜鸟教程"})
WriteResult({ "nInserted" : 1 })
> show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
runoob  0.000GB

The default database in MongoDB is test. If you do not create a new database, the collection will be stored in the test database.

注意: In MongoDB, collections are created only after content has been inserted! That is, after the collection (data table) is created, another document (record) is inserted before the collection is really created.

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.