Creating and Deleting MongoDB Database

Author: Al-mamun Sarkar Date: 2020-09-11 09:58:04

In this lesson, I will show you how to create a database on MongoDB as well as how to delete a database from the MongoDB server. 

 

Run mongo command to enter into mongo shell:

mongo

 

Create Database:

Syntax:

use database_name

Example:

use school

 

Insert data to a collection:

db.users.insert({"name":"Mamun", "email": "mamun@gmail.com"})

 

Drop Database:

Go to the database by running the following command.

use school

Delete the database:

db.dropDatabase()

Output:

{ "dropped" : "school", "ok" : 1 }

 

Show databases:

show dbs