mongodb how to delete a database code example

Example 1: drop mongo database

// First show what databases have you gotten 
show dbs
// then, use the database name that you want to drop
use YOUR_DATABASE_NAME
// now you can drop it
db.dropDatabase()
// show collections should be empty now
show collections

Example 2: drop database mongodb command line

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

Example 3: drop multiple database mongo

// if you have a list of Databases to delete then you may run the following command?


['db1', 'db2', 'db3', 'db4'].forEach(function(i){db.getSiblingDB(i).dropDatabase()})

Tags:

Go Example