To drop a collection, we can use drop of Collection.
In the following example, we first create a collection and then drop it.
use polodb_core::{bson::Document, Collection, Database};
fn main() {
let db = Database::open_memory().unwrap();
db.create_collection("name_of_the_collection").unwrap();
println!("{:?}", db.list_collection_names());
let collection: Collection<Document> = db.collection("name_of_the_collection");
collection.drop().unwrap();
println!("{:?}", db.list_collection_names());
}
Output:
Ok(["name_of_the_collection"])
Ok([])
➡️ Next: Inserting A Document
📘 Back: Table of contents