MongoDB creates a database
Grammar
MongoDB creates the database in the following syntax format:
use DATABASE_NAME
If the database does not exist, create the database or switch to the specified database.
Instance
Here's an example of us creating a database youj:
> use youj switched to db youj > db youj >
If you want to see all the databases, you can use the show dbs command:
> show dbs local 0.078GB test 0.078GB >
As you can see, the database we just created, youj, is not in the list of databases, and to display it, we need to insert some data into the youj database.
> db.youj.insert({"name":"W3Cschool教程"}) WriteResult({ "nInserted" : 1 }) > show dbs local 0.078GB youj 0.078GB test 0.078GB >
The default database in MongoDB is test, and if you don't create a new database, the collection will be stored in the test database.