Skip to main content
Records are individual data entries within a collection. Each record contains field values defined by its parent collection’s schema and provides methods for data access, manipulation, and validation.

Record structure

A record consists of:
  • Collection reference - The parent collection defining the schema
  • Field data - Values for each field defined in the collection
  • System fields - Auto-managed fields like id, created, updated
  • Expand data - Resolved relation field data
  • Custom data - Additional fields not defined in the collection schema

Creating records

You create new records through the collection:
The record id is automatically generated when you save a new record. It’s a 15-character lowercase alphanumeric string by default.

Reading field values

PocketBase provides multiple methods for accessing record data:

Basic getters

Raw getters

JSON unmarshaling

Setting field values

You can set field values using various methods:

Field modifiers

Some fields support modifier operations:

Working with files

File fields require special handling:

Uploading files

Accessing uploaded files

File URLs

Files are stored at:
For protected files, you need a file token:

Auth record helpers

Auth collections have additional convenience methods:
Changing the password or email automatically refreshes the tokenKey, which invalidates all existing authentication tokens for that user.

Relations and expand

Relation fields reference records from other collections. You can expand (resolve) these relations:

Expanding relations

Setting expand data manually

Record validation

Records are validated automatically during save operations:

Record hooks

Intercept record operations with hooks:
Available record hooks:
  • OnRecordValidate - Before validation
  • OnRecordCreate / OnRecordUpdate / OnRecordDelete - Before operation
  • OnRecordCreateExecute / OnRecordUpdateExecute / OnRecordDeleteExecute - During database write
  • OnRecordAfterCreateSuccess / OnRecordAfterUpdateSuccess / OnRecordAfterDeleteSuccess - After success
  • OnRecordAfterCreateError / OnRecordAfterUpdateError / OnRecordAfterDeleteError - After error

Querying records

Updating records

Partial updates

To update only changed fields:

Deleting records

Deleting a record also deletes associated files and handles cascade deletion for related records if configured.

Record serialization

Public export

Custom visibility

JSON marshaling

Record state management

Best practices

Always validate data before setting it on records. Use collection field constraints and custom validation logic to ensure data integrity.
Prefer GetString(), GetInt(), etc., over Get() to avoid type assertion errors and benefit from automatic type conversion.
Always check if expanded relations exist before accessing them. Missing or deleted related records can cause errors.
For multiple files, consider uploading them in batches. Large file uploads should be handled with proper error handling and retry logic.
Implement business logic in record hooks rather than scattering it throughout your codebase. This ensures consistency and maintainability.
Only use SaveNoValidate() when you’re certain the data is valid, such as system-generated updates or data migrations.