Fields, relations, indexes, and validation
Configure PocketBase fields and relations with predictable values, cardinality, and validation behavior.
Use this reference while designing a collection schema. It summarizes the field behavior evidenced by PocketBase's public collection documentation and core field tests; collection-specific options such as requiredness, uniqueness, and length limits should be set deliberately in the Dashboard or schema definition.
Field behavior
Most fields are non-nullable and use a type-specific zero value when absent. Choose the field type that matches the value clients will send and query.
| Type | Stored value | Zero or default value | Validation and modeling notes |
|---|---|---|---|
text | String | "" | Text input is normalized to a string by field preparation. |
number | Number or float | 0 | Supports numeric updates with fieldName+ and fieldName-. |
bool | Boolean | false | Stores one boolean value. |
email | Email string | "" | Use for email addresses; Auth collections also have a system email field. |
url | URL string | "" | Stores one URL value. |
editor | HTML-formatted string | "" | Treat submitted HTML as content that needs appropriate sanitization and display policy. |
date | RFC3339-like datetime string | "" | Date filters compare the full datetime string. |
autodate | Automatically assigned datetime | Product-managed | Use for created and updated timestamps. |
select | String or string array | "" or [] | Single selection is a string; multiple selection is an array. |
file | File name or file-name array | "" or [] | The database stores names; file content uses configured storage. |
relation | Record ID or ID array | "" or [] | Select one or multiple records with MaxSelect. |
json | Serialized JSON | null | The nullable exception among the documented field defaults. |
geoPoint | {lon,lat} JSON object | {lon: 0, lat: 0} | Store longitude and latitude explicitly. |
Relations and cardinality
Set MaxSelect to 1 or less for a single relation. Its stored value is one record ID or "". Set it to 2 or more for a multiple relation. Its stored value is an array of IDs or []. The same cardinality distinction applies to multiple select and file fields.
Use field modifiers when updating arrays incrementally: fieldName+ appends, +fieldName prepends, and fieldName- removes values. For example, a relation update can add USER_ID with { "users+": "USER_ID" }. Use real record IDs from your collection; the placeholder is not a literal ID.
Indexes and validation
Add an index when a field is frequently filtered, sorted, or used in a relation lookup. Add a uniqueness constraint only when duplicate values would violate the domain model. Validate required values and allowed choices at the field level, then use API rules for who may submit or change them. These controls solve different problems: validation protects shape, while rules protect authority and visibility.
For date filters, use the complete date-time format. A day-range filter can be expressed as created >= '2024-11-19 00:00:00.000Z' && created <= '2024-11-19 23:59:59.999Z'.
Verify a schema
After saving a collection, confirm that a single relation returns a string ID, a multiple relation returns an array, missing scalar fields use the intended zero value, and invalid required or constrained values produce a validation error. Then test the corresponding list, view, create, update, and delete rules with the intended guest and authenticated identities.
Continue with API rules and filters and working with records and queries.