Today in this article, we will learn how to create database in MongoDB. Let’s go through the steps in detail:
Table of Contents
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;
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;
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;
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()
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 :
- Install MongoDB in Redhat Linux with 5 Easy Steps:
- Understanding the Difference Between RDBMS and MongoDB: 4 top features
Pingback: Mongoexport and Mongoimport with Examples: Easy Guide