Collection types
PocketBase supports three distinct collection types, each designed for specific use cases:Base collections
Base collections are the standard collection type for storing general-purpose data. They provide a flexible structure with customizable fields and automatic ID generation.- Automatically includes an
idfield (15-character lowercase alphanumeric string) - Supports all available field types
- Ideal for most data storage needs
Auth collections
Auth collections are specialized for user authentication and management. They come with built-in authentication fields and support multiple authentication methods.id- Unique record identifieremail- User email address (unique when not empty)emailVisibility- Controls whether email is publicly visibleverified- Email verification statuspassword- Hashed password (hidden from API responses)tokenKey- Internal token for session management (hidden)
Auth collection IDs are unique across all auth collections to prevent conflicts during authentication.
- Password authentication
- OAuth2 (Google, Facebook, GitHub, etc.)
- One-time password (OTP)
- Multi-factor authentication (MFA)
View collections
View collections are read-only collections based on SQL queries. They allow you to create virtual collections from complex queries without storing duplicate data.- Read-only (cannot create, update, or delete records)
- Fields are auto-generated from the query result
- Cannot have file fields
Collection structure
Every collection has the following core properties:Fields
Collections contain fields that define the structure of your data. PocketBase supports various field types:- text - Single-line text
- editor - Rich text with HTML support
- number - Integers and decimals
- bool - Boolean true/false
- email - Email with validation
- url - URL with validation
- date - Date and time
- select - Single or multiple choice from predefined options
- json - Structured JSON data
- file - File uploads (single or multiple)
- relation - References to records in other collections
- autodate - Automatically managed creation/update timestamps
Indexes
Indexes improve query performance for frequently accessed fields. You can add indexes programmatically:email and tokenKey fields.
System collections
System collections have theSystem flag set to true, which prevents:
- Renaming the collection
- Deleting the collection
- Modifying API rules (for some system collections)
_superusers- Admin users_externalAuths- OAuth2 authentication records_mfas- Multi-factor authentication data_otps- One-time password records
Collection lifecycle
PocketBase provides hooks for intercepting collection operations:OnCollectionValidate- Validation phaseOnCollectionCreate/OnCollectionUpdate/OnCollectionDelete- Before operationOnCollectionCreateExecute/OnCollectionUpdateExecute/OnCollectionDeleteExecute- During database operationOnCollectionAfterCreateSuccess/OnCollectionAfterUpdateSuccess/OnCollectionAfterDeleteSuccess- After successOnCollectionAfterCreateError/OnCollectionAfterUpdateError/OnCollectionAfterDeleteError- After error
Working with collections
Creating collections
Querying collections
Updating collections
Deleting collections
Best practices
Use descriptive collection names
Use descriptive collection names
Choose names that clearly indicate the collection’s purpose. Use lowercase and underscores for multi-word names (e.g.,
blog_posts, user_profiles).Plan your schema carefully
Plan your schema carefully
While PocketBase allows schema changes, major structural changes can be complex when you have existing data. Plan your collections and fields before implementation.
Use appropriate field types
Use appropriate field types
Select field types that match your data. For example, use
date for timestamps, number for quantities, and email for email addresses to benefit from built-in validation.Set API rules early
Set API rules early
Define API rules during development to avoid accidentally exposing sensitive data. Start restrictive and relax rules as needed.
Index frequently queried fields
Index frequently queried fields
Add indexes to fields used in filters, sorts, or joins to improve query performance. However, avoid over-indexing as it can slow down write operations.