Batch Delete
Batch Operations
Batch Delete
Delete multiple documents matching IDs or filter criteria
DELETE
Batch Delete
Overview
The batch delete endpoint allows you to delete multiple documents in a single request using either an array of document IDs or a filter query. All matched documents are permanently deleted.Request
The name of the collection containing the documents to delete
Array of document IDs to delete. Either
ids or filter must be provided.Maximum: 1000 IDs (configurable)MongoDB-style filter query to match documents to delete. Either
ids or filter must be provided.Delete by IDs Example
Delete by Filter Example
Response
Number of documents that were successfully deleted
Response Example
Delete Behavior
Permanent Deletion
Deleted documents are permanently removed from the collection. For collections with versioning enabled, a snapshot is saved before deletion.Version Snapshots
Fromhandlers_batch.go:546-556:
For collections with versioning enabled, the current state of each document is saved as a version snapshot before deletion. This allows for potential recovery through the version history.
Hook Execution
Fromhandlers_batch.go:559-595:
- Pre-delete hooks: Executed for each document before deletion (best-effort in batch mode)
- Post-delete hooks: Executed after successful deletion with the total deleted count
- Hook failures do not prevent the deletion from proceeding
RBAC Filter Combination
Fromhandlers_batch.go:541-544:
The provided filter/IDs are combined with RBAC query filters to ensure users can only delete documents they have permission to access.
Filter Query Syntax
Thefilter parameter supports MongoDB query operators:
$eq,$ne: Equal, not equal$gt,$gte,$lt,$lte: Comparison operators$in,$nin: Array membership$and,$or,$not: Logical operators$exists: Field existence check$regex: Pattern matching
Safety Considerations
Best Practices
- Test filters first: Use the Count endpoint to verify how many documents will be deleted
- Use specific filters: Avoid overly broad filters that might delete more than intended
- Enable versioning: Configure versioning for collections where you might need to recover deleted data
- Implement soft deletes: Consider adding a
deletedfield and filtering it in queries instead of hard deletes
Validation
- Permission Check: User must have
deletepermission for the collection - Request Validation: Either
idsorfiltermust be provided (not both) - Batch Size: Maximum 1000 IDs if using
idsparameter - RBAC Enforcement: Only documents the user has permission to delete are affected
Error Responses
Error code:
collection_not_found: Collection does not existforbidden: User lacks delete permissionbad_request: Invalid request (missing ids/filter, invalid IDs, batch size exceeded)internal_error: Database operation failed
Human-readable error message
Additional error context
Error Examples
Audit Logging
All batch delete operations are logged to the audit trail with:- User ID and roles
- Collection name
- Filter criteria or IDs
- Number of documents deleted
- Timestamp
handlers_batch.go:597-602
Code Reference
Implementation:pkg/api/handlers_batch.go:461-610
Related Endpoints
- Batch Create - Create multiple documents
- Batch Update - Update multiple documents
- Count Documents - Count matching documents
- Delete Document - Delete a single document