When to use base collections
Use base collections when you need to:- Store general application data (posts, products, comments, etc.)
- Create custom data structures without authentication features
- Build relationships between different data types
- Store file uploads alongside other data
If you need user authentication, use auth collections instead. For read-only data from SQL queries, use view collections.
Creating a base collection
Create a base collection using the factory function:- Type set to
"base" - A default
idfield (15-character lowercase alphanumeric) - Empty fields list ready for your custom fields
With a custom ID
You can optionally specify a custom collection ID:Collection IDs are automatically generated based on the type and name if not specified. The ID format is
pbc_ followed by a CRC32 checksum.Default fields
Every base collection automatically includes anid field:
- Is automatically generated for new records
- Cannot be changed after creation
- Serves as the primary key for the collection
- Is always required and system-managed
Complete example
Here’s a complete example of creating a blog posts collection:Field configuration
Base collections support all available field types. Here are some common patterns:Text fields with validation
Numeric fields with constraints
Relations to other collections
File uploads
Setting API rules
Control access to your collection with API rules:1
Allow public read access
2
Require authentication for writes
3
Owner-only updates and deletes
Common rule patterns
Adding indexes
Indexes improve query performance for frequently searched fields:Index parameters
- Name: Unique identifier for the index
- Unique: Whether the index enforces uniqueness
- Columns: SQL expression for indexed columns (use backticks)
- Where: Optional WHERE clause for conditional indexes
Updating collections
You can modify existing collections by finding them first:PocketBase handles schema migrations automatically when you save collection changes. Existing data is preserved when adding new fields.
Best practices
- Naming
- Validation
- Security
- Performance
- Use plural names for collections (
posts,users,categories) - Use snake_case or camelCase for field names
- Keep names descriptive but concise
Next steps
Auth collections
Add user authentication to your app
Fields reference
Explore all available field types
View collections
Create read-only SQL-based collections
API rules
Learn about the rule syntax