deleteMany()

Reference type:Cheat sheetFormat:Syntax + example + use case

Reference group: Collection CRUD methods

What it does

Deletes all matching documents.

Syntax

db.collection.deleteMany(filter)

Use case

Apply retention or clean test data.

Important notes

Verify filter and expected count before destructive writes.

deleteMany(): practical example
db.auditEvents.deleteMany({ createdAt: { $lt: cutoffDate } })
💡 Explanation Deletes all matching documents. When to use it Apply retention or clean test data. Caution Verify filter and expected count before destructive writes.
Key Takeaways
  • Deletes all matching documents.
  • Typical use: Apply retention or clean test data.