Python MongoDB Delete Collection

Delete Collection

You can use drop() The method deletes the table or collection called in MongoDB.

Instance

Delete "customers" collection:

import pymongo
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["mydatabase"]
mycol = mydb["customers"]
mycol.drop()

Run Instance

If the collection is successfully deleted then drop() The method returns true if the collection does not exist, otherwise it returns false.