Create Database in MongoDB in 3 Easy steps

Today in this article, we will learn how to create database in MongoDB. Let’s go through the steps in detail:

Create Database Steps in MongoDB :

Step 1: Check the status and connect

Check the status of MongoDB is running and connect to that :

ps -ef|grep mongod
mongo
MongoDB Enterprise > show dbs;
Create Database in MongoDB in 3 Easy steps

Step 2: Issue the use Command

Now issue the below command bt you won’t see the db is listed

show dbs;
use <db_name>;
db
show dbs;
Create Database in MongoDB

Step 3: Insert Data

Now, you need to insert some data. Let’s say we are inserting data in test collection as below :

db.<collection_name>.insert({"EmpNo" : 1, "John" : "Bangalore"})
db.<collection_name>.find();
show dbs;
Create Database in MongoDB in 3 Easy steps

Now, you will be able to see the database in list.

Drop Database in MongoDB :

If you want to drop the database, use the below command :

use <db_name>
db.dropDatabase()
Create Database in MongoDB in 3 Easy steps

Hope this article helps. For more info or other ways to create MongoDB, you can also go through the MongoDB Official Link.

Related MongoDB Articles :

This Post Has One Comment

Leave a Reply