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

coffee-grinder picture coffee-grinder · Jan 13, 2012 · Viewed 450.3k times · Source

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

Answer

Tim Gautier picture Tim Gautier · Jan 13, 2012

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