In this article, you will learn all about the Python MongoDB Drop method to drop single or multiple Collections. In the previous tutorial, we have seen all about how to delete documents from MongoDB.
Python PyMongo provides a drop function to delete collections from the MongoDB database.
To delete collection ( Database ) from MongoDB, you have to use the drop() method.
Note:- If you deleted the MongoDB collection, Then documents will also be deleted.
Example: Delete Collection from MongoDB using Python
import pymongo client = pymongo.MongoClient("mongodb://localhost:27017/") # database database = client["programmingfundadb"] # collection collection = database["employees"] result = collection.drop() print(result)
The drop() method returns
True if the collection dropped successfully otherwise it returns
So, here we have seen all about how to drop MongoDB collection using the
drop() method. The
drop() method returns True if the collection is deleted successfully otherwise it returns False.
If you like this article, please share, support, and keep visiting for further Python MongoDB tutorials.
Reference:- Click Here
Thanks for reading…