Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Saturday 1 August 2015

How to create database in Mangodb

In other database when we need to create a database then we usually use CREATE DATABASE keywords. But in Mongodb we need to use USE DATABASE_NAME keyword to create a database.
If it is exist in the system then it will take you into the existing database otherwise create a new one.

Basic syntax to create database:-

USE DATABASE_NAME


Example can be:-

If you need to create database called EMPLOYEE:-

USE EMPLOYEE

It will prompt you as "switched to db EMPLOYEE"

If you want to see in which database you are in then just type "db".

If you want to see in database list that you have then just type "dbs".


In above case you have created a database but it will not get listed though you have fire "dbs" command. To get listed into "dbs" command you need to insert atleast one document (table) into it.

So let's try to do it:-

db.emp.insert({"EMPLOYEE_DETAILS":"EMPLOYEE DETAILS"})


Please provide your feedback in the comments section above. Please don't forget to follow.