MongoDB Tutorial - MongoDB Create Database

MongoDB's use DATABASE_NAME command is used to create database.

The command will create a new database, if it doesn't exist. Otherwise it will return the existing database.


Basic syntax of use DATABASE statement is as follows:



Run mongo.exe to start the client.

To create a database with name mydb, then use DATABASE statement would be as follows:

>use mydb
switched to db mydb

To check your currently selected database use the command db


To check your databases list, then use the command show dbs.

>show dbs
local     0.72222GB
test      0.22222GB

Empty database (mydb) is not present in list. To display database, insert some data into it.

>show dbs
local      0.72225GB
mydb       0.22222GB
test       0.23012GB

In mongodb default database is test. If you didn't create any database then collections will be stored in test database.