MongoDB Create DataBase

The MongoDB Create DataBase statement is used to create a new database in MongoDB.

Create DataBase Syntax :

The syntax of the Create DataBase is −

use database_name


Create DataBase Example :

The Example of the Create DataBase is −

Note:-If the database name already exists than "use" command will connect you to the database, but if the database does not exist, the command will create a new database.

use mydb;


If you want to check the currently connected database than type "db" command. The command will show the currently connected database name. The command is very helpful when a user connects to multiple databases.

\\Currently connected database
> db
mydb
-------------------
-------------------
\\list down all the databases and their size on the disk.
> show dbs
admin  0.000GB
local  0.000GB  


The database is not created until you save a document in it, now we are creating an collection user and inserting a document into it.

> db.user.insert({name: "mayank", age: 26})
WriteResult({ "nInserted" : 1 })
> show dbs
admin          0.000GB
mydb           0.000GB
local          0.000GB




Visit :


Discussion



* You must be logged in to add comment.