Drop a MongoDB database from the command line
You can drop a database in MongoDB from the command line using db.dropDatabase() command or a one line shell script. Let’s see how to do this.
db.dropDatabase
() command removes the current database, deleting the associated data files. This by default delete default ‘test’ database. If you have selected any database using use <db> command, then db.dropDatabase() command will drop that particular database.
You can do it in two ways.
Mongo console
> show dbs admin 0.000GB config 0.000GB local 0.000GB chat-bot 0.019GB orders 0.000GB > use orders > db.dropDatabase() { "ok" : 1 } > show dbs admin 0.000GB config 0.000GB local 0.000GB chat-bot 0.019GB
Command line as one line script
mongo <dbname> --eval "db.dropDatabase()"