Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

mongodb

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

like image 813
coffee-grinder Avatar asked Jan 13 '12 21:01

coffee-grinder


People also ask

How do I drop a data database in MongoDB?

Then you can use “show dbs” command for checking the list of Databases. Then select the database you want to delete using command “use databasename“. Then execute db. dropDatabase() command to drop an existing database.

Which method is used to drop a database in MongoDB?

MongoDB db. dropDatabase() command is used to drop a existing database.

How do I delete an entire collection in MongoDB?

To delete a MongoDB Collection, use db. collection. drop() command.


1 Answers

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

like image 89
Tim Gautier Avatar answered Oct 06 '22 23:10

Tim Gautier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!