Deleting Documents
deleteOne() removes the first matching document, deleteMany() removes every match — and an empty filter {} matches everything in the collection.
Deleting one document
JS mongosh
db.posts.deleteOne({ title: "Schema Design 101" })
Output
{ acknowledged: true, deletedCount: 1 }Deleting many at once
JS mongosh
db.posts.deleteMany({ views: { $lt: 1 } })
Output
{ acknowledged: true, deletedCount: 1 }That removed every post with fewer than one view. The filter works exactly like it does in find() — if you can write a query that matches the right documents, that same filter deletes them.
The empty-filter trap:
db.posts.deleteMany({}) matches every document in the collection — an empty filter object matches everything, the same way DELETE FROM posts with no WHERE clause wipes an entire SQL table. There's no confirmation prompt; it just runs. Double-check your filter before hitting enter on a deleteMany.