Hello Programmers! In previous chapter we were introduced with MongoDB. Now we know that MongoDB is NoSQL database program that provides a mechanism for storage and retrieval of data in documents of tree structured collections.

MongoDB Tutorials - how to create-remove database using MongoDB shell
MongoDB Tutorials : How to create/remove database using MongoDB shell? - progrramers


In this MongoDB Tutorial we will see how to create a Database in MongoDB.

use Command

In MongoDB ‘use command’ is used to create database. ‘use Command’ is also used to switch to another existing database. The command creates a new database if database is not existing otherwise it returns existing database.

Below is the basic syntax of use command :

use <database_name>

> use cricket
switched to db cricket
>


Above is example of use command that shows how to create a new to database.

db Command

db command shows the name of database that currently in use. By default ‘test’ database is selected but you can switch to other existing database by using ‘use command’.


> db
cricket
>




show dbs Command

Show dbs command shows the list of database existed in MongoDB.


> show dbs
admin 0.078GB
cars 0.078GB
company 0.078GB
cricket 0.078GB
demo 0.078GB
local 0.078GB
myapp 0.078GB
mydb 0.078GB
school 0.078GB
test 0.078GB
>


Note: When you create new database using use command and then check the database list using show dbs, you will not find the new created database in this list until you do not create at least a collection in that database. By default ‘test’ database is selected if not creating new database then collection will be created and stored in ‘test’ database.

Now we will see how to drop a database using MongoDB command.

dropDatabase() Method

In MongoDB dropDatabase() method is used to drop database.

Below is the basic syntax of Drob Database Command:

dropDatabase()
Switch to existing database using ‘use’ Command and write down the command dropDatabase() and hit Enter button and your existing database is deleted.


> use demo
switched to db demo
> db.dropDatabase()
{ "dropped" : "demo", "ok" : 1 }
> show dbs
aams 0.078GB
admin 0.078GB
cars 0.078GB
company 0.078GB
cricket 0.078GB
local 0.078GB
myapp 0.078GB
mydb 0.078GB
school 0.078GB
test 0.078GB
>


dropDatabase() command deletes the selected database therefore you do not required to write any other filter criteria. If you haven’t select any database then it delete ‘test’ database by default.

Next chapter in this tutorial series will elaborate How to create/remove collection using MongoDB Shell?
progrramers-logo

progrramers

Hello friends! Progrramers is a tutorial site of w3 programming. If you like this tutorial site please encourages us by sharing this site links with your friends and nears & dears who want to learn web development and give us like on our Facebook page. If have any question please type in to comment box or send us message on social media sites via below given social links. Thank you, have a nice learning.

Post A Comment:

5 comments:


  1. A tableau could be a tool used for information visual image in business. It merely converts the data into a really understanding format. By this tableau, we will simply and fastly analyze the information likewise. we will simply learn this tableau with certification at 360DigiTMG in Hyderabad with extremely qualified and practiced school. begin doing the course currently and obtain certified shortly.
    tableau training

    ReplyDelete
  2. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own Blog Engine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
    click here

    ReplyDelete
  3. Tableau training institute in Hyderabad can be a ticket to your fortunate tableau career. Dashboards, tableau desktop, Tableau online ,charts ,and many other key features of tableau this is best for you have interest visit my website link http://tableautrainings.in/

    ReplyDelete

  4. Useful Article
    Thanks for sharing best content with us
    Visit my site for learning:
    SAP SD Training in Hyderabad

    ReplyDelete
  5. "Your article is highly valuable. Thank you for sharing such insightful content with us. Feel free to visit my website for additional learning resources."visit:
    Mulesoft Training In Hyderabad

    ReplyDelete