Get Document
Document Operations
Get Document
Retrieve a single document by its unique identifier
GET
Get Document
Overview
Fetch a specific document from a collection by its_id. The endpoint:
- Validates document permissions before returning data
- Applies field-level access controls
- Masks sensitive fields based on user role
- Calculates computed fields
- Logs read access to audit trail (if enabled)
Request
Path Parameters
The name of the collection containing the document
The unique identifier (_id) of the document. Can be MongoDB ObjectId or any string ID.
Headers
Bearer token for authentication
Response
The document’s unique identifier
ISO 8601 timestamp when the document was created
ISO 8601 timestamp when the document was last updated
User ID of the user who created the document
All other fields from the document, filtered by field-level permissions and masking rules
Examples
Get by ObjectId
Get by String ID
Response
email field is masked based on the user’s role permissions.
Implementation Details
MongoDB Query Pattern
The handler uses MongoDB’sfindOne operation:
Workflow
- Extract collection and ID from URL path (handlers_crud.go:195-196)
- Validate parameters - collection and ID required (handlers_crud.go:198-205)
- Authenticate request and get auth context (handlers_crud.go:208)
- Validate collection exists in schema (handlers_crud.go:214)
- Fetch document from MongoDB (handlers_crud.go:227)
- Handle not found - return 404 if document doesn’t exist (handlers_crud.go:229)
- Handle invalid ID - return 400 for malformed IDs (handlers_crud.go:236)
- Check RBAC permissions - verify user can read this specific document (handlers_crud.go:249)
- Log audit event if log_reads enabled (handlers_crud.go:258)
- Calculate computed fields - virtual fields not stored in DB (handlers_crud.go:261)
- Apply field policy - remove denied fields (handlers_crud.go:264)
- Apply field masking - mask sensitive data (handlers_crud.go:267)
- Return document with 200 OK (handlers_crud.go:270)
Field-Level Access Control
Fields are filtered based on role policies:Field Masking
Sensitive fields are masked based on role permissions:email: Shows first char and domain (e.g.,j***@example.com)phone: Shows last 4 digits (e.g.,***-***-1234)partial: Shows first and last char (e.g.,j***n)full: Replaces with***
Computed Fields
Virtual computed fields are calculated on-the-fly:RBAC Permission Check
The system checks if the user can read this specific document:- Owner-only:
resource.created_by == user.id - Tenant isolation:
resource.company_id == user.tenant_id - Department access:
resource.department in user.departments - Hierarchical:
resource.owner_id in user.subordinates
Error Responses
400 Bad Request
Returned when ID format is invalid:401 Unauthorized
403 Forbidden
Returned when user doesn’t have permission to read this document:404 Not Found
Returned when document or collection doesn’t exist:500 Internal Server Error
Use Cases
Profile Page
View Details
Check Status
Related Endpoints
- List Documents - Query multiple documents
- Update Document - Modify the document
- Delete Document - Remove the document
- Create Document - Create a new document