-->

DEVOPSZONES

  • Recent blogs

    How to delete or drop MongoDB database

    How to delete or drop MongoDB database


    In this MongoDB Tutorial, we shall learn to drop or delete a MongoDB Database.

    To delete or drop a database from MongoDB, follow the below steps :

    1. Select the database you want to delete with following "USE <database>" command. 

    Following is the syntax of USE command : use <database_name>

    2. Drop the database with following "db.dropDatabase()" command. 

    Following is the syntax of dropDatabase command : db.dropDatabase()


    MongoDB Drop database


    Check all the Databases:


    > show dbs;
    admin      0.000GB
    config     0.000GB
    dev_xxxxx   0.000GB
    local      0.000GB
    prod_xxxxx  0.000GB
    testing    0.000GB

    Select the DB you want to Delete:

    > use prod_xxxxx;
    switched to db prod_xxxxx

    DROP the Database:

    > db.dropDatabase()
    { "dropped" : "prod_xxxxx", "ok" : 1 }

    Check all the Databases Again:

    > show dbs;
    admin     0.000GB
    config    0.000GB
    dev_xxxxx  0.000GB
    local     0.000GB
    testing   0.000GB

    No comments