Latest web development tutorials

Create a database MongoDB


MongoDB database creation syntax is as follows:


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


The following example we create a database w3big:

> use w3big
switched to db w3big
> db

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

> show dbs
local  0.078GB
test   0.078GB

You can see that we just created database w3big not in the list of databases, to show it, we need to insert some data w3big database.

> db.w3big.insert({"name":"本教程"})
WriteResult({ "nInserted" : 1 })
> show dbs
local   0.078GB
w3big  0.078GB
test    0.078GB

MongoDB in the default database to test, if you do not create a new database, the collection will be stored in the test database.