mongo //to start the mongodb shell
show dbs //to list existing databases
use <dbname> //the <dbname> is the database you'd like to drop
db //should show <dbname> just to be sure I'm working with the right database
db.dropDatabase() //will delete the database & return { "dropped" : "<dbname>", "ok" : 1 }
mongo // To go to shell
show databases // To show all existing databases.
use <DATA_BASE> // To switch to the wanted database.
db.dropDatabase() // To remove the current database.
MAC:FOLDER USER$ mongodb> show databaseslocal 0.78125GBmydb 0.23012GBtest 0.23012GB> use mydbswitched to db mydb>db.dropDatabase(){ "dropped" : "mydb", "ok" : 1 }>
import argparse
import pymongo
if __name__ == "__main__":"""Drop a Database."""
parser = argparse.ArgumentParser()parser.add_argument("--host", default='mongodb://localhost:27017',help="mongodb URI [default: %(default)s]")parser.add_argument("--database", default=None,help="database name: %(default)s]")
args = parser.parse_args()
client = pymongo.MongoClient(host=args.host)
if args.database in client.list_database_names():client.drop_database(args.database)print(f"Dropped: '{args.database}'")else:print(f"Database '{args.database}' does not exist")