Restore Version
Version History
Restore Version
Restore a document to a previous version
POST
Restore Version
Restores a document to the state it had at a specific version. This creates a new version with the restored data.
Endpoint
Path Parameters
The name of the collection containing the document
The unique identifier of the document
The version number to restore to (must be >= 1)
Authentication
Requires valid authentication. The user must have therestore action permission on the collection and access to the specific document.
Restore Process
When you restore a document:- Pre-restore Snapshot: The current state is saved as a new version with change reason “Pre-restore snapshot”
- Data Retrieval: The specified version’s data is reconstructed
- Pre-update Hooks: Executed with action “restore”
- Document Update: The document is updated with the restored data
- Post-update Hooks: Executed with action “restore”
- Audit Logging: The restore action is logged with before/after states
- New Version: A new version is created with the restored data
Response
Returns the restored document with updated metadata.Document identifier (preserved from original)
New version number after restore
ISO 8601 timestamp when the restore was performed
User ID who performed the restore
All other document fields from the restored version
Example Request
Example Response
Version Timeline Example
Here’s what happens during a restore operation:Important Behaviors
Document ID Preservation
The document’s_id is always preserved during restore. Only the data fields are restored.
Metadata Updates
The following fields are automatically updated:updated_at: Set to the current timestampupdated_by: Set to the user performing the restore
Pre-restore Snapshot
If versioning is enabled for the collection, the current document state is saved as a version before restoring. This ensures you can undo the restore if needed.Hooks Integration
Restore operations trigger hooks with:- Action:
restore - Before: Current document state
- After: Restored document data
- Metadata: Includes
document_idandrestore_version
- Validate the restore operation
- Modify the restored data
- Send notifications
- Trigger external workflows
Audit Trail
The restore action is logged with:- Action type:
restore - Before and after document states
- Field-level changes computed
- User who performed the restore
- Success/failure status
Error Responses
Bad Request - Invalid parameters or hook validation failed
Unauthorized - Authentication required
Forbidden - Missing restore permission
Not Found - Document or version not found
Internal Server Error - Failed to restore document
Not Implemented - Versioning is not enabled
Permission Requirements
The restore action requires:- Authentication: Valid user credentials
- Collection-level:
restoreaction permission - Document-level: RBAC conditions must pass for the specific document
Use Cases
- Undo Changes: Revert accidental modifications
- Rollback: Return to a known good state after issues
- Data Recovery: Restore deleted or corrupted data
- Compliance: Meet regulatory requirements for data retention
- Testing: Restore to a baseline state for testing
- Comparison: Restore temporarily to compare with current state
Best Practices
- Verify Before Restoring: Use the diff endpoint to review changes before restoring
- Check Permissions: Ensure users only restore when appropriate
- Monitor Restores: Log and alert on restore operations for audit purposes
- Document Reasons: Consider adding a change_reason when possible
- Test Hooks: Ensure pre/post hooks handle restore actions correctly
- Backup Strategy: Rely on the pre-restore snapshot as a safety net
Notes
- The restored document becomes the new current version
- Previous versions remain intact and accessible
- Field-level policies apply to the returned document
- The restore operation is atomic - either fully succeeds or fails
- Post-restore hooks run asynchronously and are best-effort