List Documents
Document Operations
List Documents
Query and list documents with filtering, pagination, sorting, and field projection
GET
List Documents
Overview
Retrieve a paginated list of documents from a collection with support for:- Filtering - Query documents by field values
- Cursor-based pagination - Efficient pagination for large datasets
- Sorting - Order results by one or more fields
- Field projection - Select specific fields to return
- RBAC filtering - Automatic query filtering based on user permissions
- Field masking - Sensitive data protection
Request
Path Parameters
The name of the collection to query
Query Parameters
Maximum number of documents to return. Cannot exceed
max_result_size (default 10000)Pagination cursor from previous response to fetch next page. Base64-encoded cursor data.
Comma-separated list of fields to sort by. Prefix with
- for descending order.Examples:created_at- Sort by created_at ascending-created_at- Sort by created_at descendingstatus,-created_at- Sort by status ascending, then created_at descending
Comma-separated list of fields to include in response.
_id is always included.Example: name,email,created_atFilter by any field in your schema. Supports:
- Simple equality:
?status=active - JSON values for complex types:
?age={"$gt":18} - Multiple fields:
?status=active&role=admin
Headers
Bearer token for authentication
Response
Examples
Basic List
With Filtering
With Sorting
With Field Projection
Pagination (Next Page)
Complex Filter with JSON
Response Example
Implementation Details
MongoDB Query Pattern
The handler uses MongoDB’sfind operation with cursor-based pagination:
Workflow
- Extract collection name from URL path (handlers_query.go:146)
- Authenticate request and get auth context (handlers_query.go:153)
- Validate collection exists in schema (handlers_query.go:160)
- Check RBAC read permission (handlers_query.go:169)
- Parse query parameters into filter, sort, limit, cursor, fields (handlers_query.go:178)
- Get RBAC query filter based on user’s roles (handlers_query.go:186)
- Combine user filter with RBAC filter using $and (handlers_query.go:191)
- Apply cursor-based pagination if cursor provided (handlers_query.go:194)
- Build MongoDB sort specification (handlers_query.go:207)
- Execute query with limit+1 to detect hasMore (handlers_query.go:229)
- Calculate computed fields for each document (handlers_query.go:246)
- Apply field policy to hide denied fields (handlers_query.go:247)
- Apply field masking for sensitive data (handlers_query.go:248)
- Get total count (only on first page, can be expensive) (handlers_query.go:256)
- Build next cursor from last document (handlers_query.go:264)
- Return paginated results (handlers_query.go:285)
Cursor-Based Pagination
The system uses efficient cursor-based pagination instead of offset-based pagination:RBAC Query Filtering
The system automatically filters queries based on user permissions:Field Projection
Optimize bandwidth by selecting specific fields:Error Responses
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
500 Internal Server Error
Performance Considerations
Indexes
For optimal performance, create indexes on:- Fields used in filters
- Fields used in sorting
- Compound indexes for multi-field sorts
Total Count
Thetotal count is only computed on the first page (when no cursor is provided) because:
- Counting can be expensive for large collections
- Count accuracy decreases with pagination depth
- Most UIs only need “has more” information
Limit Recommendations
- Default: 20 documents per page
- Maximum: 10,000 (configurable via
max_result_size) - Recommended: 20-100 for web UIs, 100-1000 for bulk operations
Related Endpoints
- Get Document - Retrieve a single document by ID
- Create Document - Create a new document
- Update Document - Modify an existing document
- Delete Document - Remove a document