In this tutorial we will learn MongoDB database creation. In our previous tutorial we learned how to connect MongoDB database with php. MongoDB provides us default database as test. if you will not create any database then your all collection will store in test database.
In MongoDB “use DATABASE_NAME” used for create database. If you used command then database will be create if it does not exist.
Syntax to create database :
If you use above command on MongoDB shell then it will create database for you. After creating your database you need to check your database is exist or not so that need to run following command.
>show dbs Result : local 0.000 GB test 0.000 GB
If inside your database no collection available then it will not show on dbs list as above result.
Run command to insert some data inside demo db, before that make sure your current database is demo by >db it will return you demo (database name).
Command to insert data in demo db.
Now you will check your dbs list by command
Result : local 0.000 GB test 0.000 GB demo 0.000 GB
Now you can work on your database. we will learn on next tutorial.