Concept Flow - Delete all documents in collection
Start
Connect to DB
Select Collection
Run deleteMany({})
All documents removed
End
The process connects to the database, selects the collection, then deletes all documents using an empty filter.
db.collection.deleteMany({})| Step | Action | Filter Used | Documents Before | Documents Deleted | Documents After |
|---|---|---|---|---|---|
| 1 | Connect to database | - | - | - | - |
| 2 | Select collection | - | - | - | - |
| 3 | Run deleteMany | {} | 5 | 5 | 0 |
| 4 | Verify deletion | - | 0 | 0 | 0 |
| Variable | Start | After deleteMany | Final |
|---|---|---|---|
| documents_count | 5 | 0 | 0 |
Syntax: db.collection.deleteMany({})
Deletes all documents because empty filter matches all.
Use with caution: removes everything.
Returns count of deleted documents.
Verify with find() after deletion.