In MongoDB ‘use command’ is used to create database. ‘use Command’ is also used to switch to another existing database.dropDatabase() command deletes the selected database therefore you do not required to write any other filter criteria. - progrramers explained
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. Really nice and interesting post. I was looking for this kind of information and enjoyed reading this one. Keep posting. Thanks for sharing.
    data science course in guduvanchery

    ReplyDelete
  3. 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
  4. Thank you for sharing the article. The data that you provided in the blog is informative and effective.

    Tableau Training in Hyderabad

    ReplyDelete