Batch Create
Batch Operations
Batch Create
Create multiple documents in a single request with validation and hooks support
POST
Batch Create
Overview
The batch create endpoint allows you to insert multiple documents into a collection in a single atomic operation. Each document is validated against the collection schema, and pre/post-create hooks are executed for each document.Request
The name of the collection to insert documents into
Array of documents to create. Each document is a JSON object with field values matching the collection schema.Maximum batch size: 1000 documents (configurable)
Request Example
Response
Array of document IDs that were successfully created
Response Example
Batch Processing Details
Automatic Fields
Each document automatically receives:created_by: Set to the authenticated user’s IDcreated_at: Set to current UTC timestampupdated_at: Set to current UTC timestamp- Tenant/owner fields (if configured in collection schema)
Validation
- Schema Validation: Each document is validated against the collection schema
- Permission Check: User must have
createpermission for the collection - Batch Size Limit: Maximum 1000 documents per request (default, configurable)
- Pre-create Hooks: Executed for each valid document before insertion
Partial Success
Batch create supports partial success:- Documents that pass validation are inserted
- Documents that fail validation are returned in the
failedarray - The operation does not roll back on partial failures
Hook Execution
Fromhandlers_batch.go:212-284:
- Pre-create hooks are executed for each document before insertion
- If a pre-create hook fails, that document is not inserted
- Post-create hooks are executed after successful insertion (best-effort)
- Hook failures do not affect other documents in the batch
Error Responses
Error code:
collection_not_found: Collection does not existforbidden: User lacks create permissionbad_request: Invalid request format or batch size exceededschema_validation: One or more documents failed validation
Human-readable error message
Additional error context (batch size, validation errors, etc.)
Error Example
Code Reference
Implementation:pkg/api/handlers_batch.go:113-300
Related Endpoints
- Batch Update - Update multiple documents
- Batch Delete - Delete multiple documents
- Create Document - Create a single document