Quick Contact

    MongoDB Tutorial

    How MongoDB Drop Database with DropDatabase() Method

    MongoDB Drop Database

    In MongoDB Drop Database, a command is used to drop the database from it. For this purpose, we can use a dropDatabase command. The user must know that it also deletes the data files associated with it. It operates on the current database or let us say selected database.

    1. List the Database

      First of all, you should execute show dbs command to know if your database exists in MongoDB. For example,

      > show dbs

      local 0.52938GB

      ducat 0.49231GB

      test 0.49231GB

      We can see that we had created a database with the name “ducat”. If your database exists, move to the next step.

    2. Check the Selected Database

      You should make sure that you have selected the database you have to delete it. Run the db command in the command prompt to know the selected database.

      >db

      ducat

      In case you have not selected the right database, you should select that.

    3. Select the Database

      You should execute the “use” command as previously discussed.

      >use ducat

      Switched to db ducat

      After doing that you can move to the next and final step.

    4. Command for Drop Database

      Here, “dropDatabase()” command is used for MongoDB drop database. It is executed on the selected database.

      >db. dropDatabase()

      { “dropped”: “ducat”, “ok”: 1}

      It shows that the database has been deleted. You can also confirm by using “show dbs” command that will enlist the existing databases.

      So, this was all about MongoDB Drop Database Tutorial. Hope you like our explanation.

    Must Read About MongoDB Tutorial.

    Copyright 1999- Ducat Creative, All rights reserved.