In this chapter, we will see the way to create a database in MongoDB.
The use Command
MongoDB use DATABASE_NAME is used to create database. The command will create a new database if it would not exist, in any other case it will go back the prevailing database.
Syntax
Basic syntax of use DATABASE statement is as follows −
use DATABASE_NAME
Example
If you need to apply a database with name <mydb>, then use DATABASE announcement might be as follows −
>use mydb
switched to db mydb
To take a look at your currently decided on database, use the command db
>db
mydb
If you need to test your databases listing, use the command show dbs.
>show dbs
local 0.78125GB
test 0.23012GB
Your created database (mydb) isn't always found in list. To show database, you want to insert at the least one file into it.
>db.movie.insert({"name":"tutorials point"})
>show dbs
local 0.78125GB
mydb 0.23012GB
test 0.23012GB
In MongoDB default database is check. If you didn't create any database, then collections can be saved in check database.