MongoDB Drop Database – How to Guide

MongoDB is a free and open-source cross-platform document-oriented database.Classified as a NoSQL database and Used In MEAN Stack development. When you’re developing and testing your app with the database you need drop database very often and for developers preferred way is to drop or remove mongo database from the command line using command but there is another way to do that using utility software called RoboMongo, we will discuss both.So let’s learn about MongoDB Drop Database using Mongo shell and Robo 3T.

First, we will discuss how to mongo drop db from command or mongodb delete database from the command line.

Article Contents

How to MongoDB Drop Database from Command line?

  • We are going to use MongoDB db.dropDatabase() command to drop or remove a database.
  • First list all the databases exist using command show dbs
  • Then select the mongo database you want to drop using use <dbname>
  • To drop selected MongoDB use command db.dropDatabase()
  • Be careful as you can delete your production db by mistake
  • Mongo shell will show success message as { "dropped" : "test", "ok" : 1 }
  • Now use show dbs commands to confirm.
    c:\mongodb\bin>mongo
    MongoDB shell version v3.4.4
    connecting to: mongodb://127.0.0.1:27017
    MongoDB server version: 3.4.4
    Server has startup warnings:
    2017-09-23T21:08:28.877+0530 I CONTROL  [initandlisten]
    2017-09-23T21:08:28.877+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
    2017-09-23T21:08:28.879+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
    2017-09-23T21:08:28.879+0530 I CONTROL  [initandlisten]
    > show dbs
    Ecommerce           0.000GB
    admin               0.000GB
    blogdb              0.000GB
    test                0.000GB
    chatDB              0.000GB
    ecomDB              0.000GB
    helloDeskDB         0.000GB
    
    > use test
    switched to db test
    > db.dropDatabase()
    { "dropped" : "test", "ok" : 1 }
    >

     

MongoDB Shell

 

How to MongoDB Drop Database Using Robo 3T or RoboMongo Utility?

You can also drop or remove or delete MongoDB database using Robo 3T or Robomongo (a free lightweight GUI for MongoDB and A MongoDB GUI with embedded shell )

  • Launch the Robo 3T on your pc
  • it will ask to choose and connect MongoDB, press connect.
  • Robo 3T will list all dbs in the left sidebar.
  • Choose the Db you want to drop from MongoDB.
  • Right-click on the selected db and choose drop database option.
  • it will ask for confirmation, press yes and you’ve successfully dropped mongo database.

Robo 3T Mongodb GUI

Thanks for reading this how-to guide on MongoDB and please comment below, if you have any queries or requests and Do subscribe to our Newsletter for awesome web development related stuff and freebies.

See also  How to Download files From Server in ExpressJS (Node.js)

Leave a Comment