How do I drop a MongoDB database from the command line?

874

What's the easiest way to do this from my bash prompt?

This question is tagged with mongodb

~ Asked on 2012-01-13 21:11:40

The Best Answer is


1103

Like this:

mongo <dbname> --eval "db.dropDatabase()"

More info on scripting the shell from the command line here: https://docs.mongodb.com/manual/tutorial/write-scripts-for-the-mongo-shell/#scripting

~ Answered on 2012-01-13 21:19:12


854

The best way to do it is from the mongodb console:

> use mydb; 
> db.dropDatabase();

Alternatively, you can stop mongod and delete the data files from your data directory, then restart.

Hint: you can also move the data files to a subfolder, and delete them if you're sure you no longer need them.

~ Answered on 2012-01-13 21:15:24


Most Viewed Questions: