Python MongoDBLesson 132Free preview
MongoDB Drop Collection
This lesson is part of Python · All levels
Summary
This lesson explains how to delete collections and databases in MongoDB using drop. The collection that is dropped is lost along with the document, index, and definition, so unlike delete_many that only deletes the document. You'll also learn how to delete the entire database.
Key points
- Db.drop_collection("name") or db["name"].drop() delete the collection along with its structure.
- The index attached to the collection is deleted when the collection is dropped.
- Delete_many({}) leaves the collection blank, while drop deletes the collection.
- Client.drop_database("name") deleted the database and its entire collection.
- The drop operation is permanent, so make sure the target's name is correct before you run it.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.