rodrigosantosbr

How to Drop a Database in MongoDB from the Command Line

Feb 3rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!

Using the Mongo Shell Utility

Begin by issuing the mongo command from your bash shell:

$ mongo
MongoDB shell version: 3.0.9
connecting to: test
>

Now that you are connected to Mongo, use the show dbs command to display all databases in the system:

> show dbs
local  0.078GB
bookstore 0.521GB

Now connect to the specific database that you wish to drop with the use <database> command. In our case, we’ll once again connect to bookstore:

> use bookstore
switched to db bookstore

Finally, execute the deletion by calling the db.dropDatabase() method, similar to our eval‘ed statement above.

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

There you have it! Two simple methods for dropping a specific database from MongoDB quickly and easily.

Add Comment
Please, Sign In to add comment