We use drop to remove a whole collection and deleteMany to remove some or all documents inside a collection without deleting the collection itself.
Drop collection vs deleteMany in MongoDB
db.collection.drop() db.collection.deleteMany(filter)
drop() removes the entire collection including indexes.
deleteMany(filter) removes documents matching the filter but keeps the collection and indexes.
users collection and all its data.db.users.drop()
users collection.db.users.deleteMany({ age: { $lt: 18 } })orders collection but keeps the collection itself.db.orders.deleteMany({})This example first inserts three products. Then it deletes products cheaper than 2 (Pen and Eraser). Next, it shows remaining products (Notebook). Finally, it drops the whole products collection and checks if it still exists.
use shopDB // Create collection and insert sample data db.products.insertMany([ { name: "Pen", price: 1.5 }, { name: "Notebook", price: 3 }, { name: "Eraser", price: 0.5 } ]) // Delete all products cheaper than 2 const deleteResult = db.products.deleteMany({ price: { $lt: 2 } }) // Check remaining documents const remaining = db.products.find().toArray() // Drop the entire collection const dropResult = db.products.drop() // Check if collection exists const collections = db.getCollectionNames()
After drop(), the collection no longer exists and must be recreated to add data again.
deleteMany({}) deletes all documents but keeps the collection and indexes intact.
Use drop() carefully because it removes everything including indexes.
drop() removes the entire collection and all data.
deleteMany(filter) removes documents matching the filter but keeps the collection.
Choose drop() to remove collection completely, deleteMany to clear data selectively.