Anubhav Agarwal
Anubhav Agarwal

Reputation: 2062

How to delete pymongo.Database.Database object

I am using pymongo to connect to mongodb in my code. I am writing a google analytic kind of application. My db structure is like that for each new website I create a new db. So when someone registers a website I create a new db with that name, however when unregistering the website I wish the database to be deleted. I remove all the collection but still the database could not be removed

And as such the list of databases is growing very large. When I do

client = MongoClient(host=MONGO_HOST,port=27017,max_pool_size=200)
client.database_names()

I see a more than a 1000 list of apps. Many of them are just empty databases. Is there a way that I remove the mongo databases ?

Upvotes: 3

Views: 4444

Answers (1)

stalk
stalk

Reputation: 12054

Use drop_database method:

client = MongoClient(host=MONGO_HOST,port=27017,max_pool_size=200)
client.drop_database("database_name")

Upvotes: 9

Related Questions