Skip to main content
Base collections are the standard collection type in PocketBase. They provide a flexible way to store any kind of structured data with custom fields and validation rules.

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:
This initializes a collection with:
  • Type set to "base"
  • A default id field (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 an id field:
This 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

Setting a rule to nil denies all access. Setting it to "" allows all access. Use filter expressions for conditional access.

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

  • 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