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

MongoDB creates database


Syntax

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

Example

In the following example we created the database php:

> use php
switched to db php
> db
php
>

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

> show dbs
local  0.078GB
test   0.078GB
>

You can see that the database php we just created is not in the list of databases. To display it we need to insert some data into the php database.

> db.php.insert({"name":"php中文网"})
WriteResult({ "nInserted" : 1 })
> show dbs
local   0.078GB
php  0.078GB
test    0.078GB
>

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

php.cn