Documentation Index
Fetch the complete documentation index at: https://mintlify.com/directus/directus/llms.txt
Use this file to discover all available pages before exploring further.
What are Collections?
Collections in Directus are analogous to tables in a traditional SQL database. Each collection represents a distinct data entity in your project, such as articles, products, users, or any custom content type you define. Collections serve as containers for items and define the overall structure of your data model.Directus maintains both a schema representation (the actual database table) and metadata (configuration for how the collection appears in the app).
How Collections Work
When you create a collection in Directus, two things happen:- Database Schema: A table is created in your SQL database with the specified structure
- Collection Metadata: Configuration is stored in
directus_collectionsto control app behavior
Collection Structure
Every collection in Directus consists of:- Collection Name: A unique identifier (maps to the database table name)
- Fields: Individual data points within the collection (columns in the database)
- Schema: The actual database table structure
- Meta: Display and behavior configuration for the Directus app
Creating Collections
Collections can be created through the API or programmatically. When creating a collection, Directus automatically adds a primary key field if you don’t specify one.API Example
Automatic Primary Key
From the source code (~/workspace/source/api/src/services/collections.ts:110-122), Directus ensures every collection has a primary key:
Collection Metadata
Collection metadata controls how collections appear and behave in the Directus app. Key metadata properties include:| Property | Type | Description |
|---|---|---|
icon | string | Icon displayed in the app navigation |
note | string | Description of the collection |
hidden | boolean | Whether to hide from navigation |
singleton | boolean | Only allows one item in the collection |
sort_field | string | Field used for manual sorting |
archive_field | string | Field that marks items as archived |
accountability | string | Track activity for items (all, activity, or null) |
translations | array | Multilingual labels for the collection |
versioning | boolean | Enable content versioning |
Singleton Collections
Singleton collections are special collections that can only contain one item, useful for settings pages or global configuration:System Collections
Directus includes built-in system collections that power core functionality:directus_users- User accountsdirectus_roles- User rolesdirectus_permissions- Access control rulesdirectus_files- File assetsdirectus_folders- File organizationdirectus_activity- Audit logdirectus_revisions- Content versioning historydirectus_collections- Collection metadatadirectus_fields- Field configurationsdirectus_relations- Relationship definitions
System collections cannot be deleted and have restricted modification capabilities to ensure platform stability.
Common Use Cases
Content Management
Create collections for blogs, articles, pages, and other content types with custom fields for titles, body text, authors, and publication dates.
E-commerce
Build product catalogs with collections for products, categories, reviews, and orders, leveraging relationships between collections.
User Directories
Extend the default user system with custom profile collections that relate to
directus_users for additional user metadata.Media Libraries
Organize media assets using collections that relate to
directus_files with additional metadata like tags, categories, or licenses.Collection Operations
Reading Collections
Retrieve all collections in your project:Updating Collections
Update collection metadata:Deleting Collections
~/workspace/source/api/src/services/collections.ts:617-677), deleting a collection also removes:
- The database table and all records
- Field configurations in
directus_fields - Permissions in
directus_permissions - Activity logs in
directus_activity - Revisions in
directus_revisions - Related relationships in
directus_relations
Grouping Collections
Collections can be organized into groups for better navigation:group field references another collection that serves as the parent group.
Best Practices
Related Concepts
- Fields - Define the structure of data within collections
- Items - Individual records stored in collections
- Relationships - Connect data across collections
- Permissions - Control access to collections