Skip to main content
Collections define the structure of your data in PocketBase. Each collection has a type, fields, and various configuration options.

Collection types

PocketBase supports three collection types:
  • base - Standard collections for general data storage
  • auth - Collections with built-in authentication features
  • view - Read-only collections based on SQL queries

Creating collections

NewCollection()

Create a new collection with the specified type:

NewBaseCollection()

Create a base collection:

NewAuthCollection()

Create an auth collection:

NewViewCollection()

Create a view collection:

Finding collections

FindCollectionByNameOrId()

Find a collection by name or ID:

FindCachedCollectionByNameOrId()

Find a collection from the app cache (faster, but read-only):
The cached collection should only be used for read-only operations. Modifying the cached collection affects the global cached value.

FindAllCollections()

Find all collections, optionally filtered by type:

Collection properties

Basic properties

Type checking

Managing fields

Adding fields

Getting fields

Removing fields

API rules

Collections have API rules that control access:
API rules use PocketBase’s filter syntax. Use nil to deny all access, or an empty string "" to allow all access.

Auth collection options

Auth collections have additional configuration:

View collection options

View collections are based on SQL queries:
View queries must include an id column. Wildcard columns are not supported to prevent accidentally exposing sensitive data.

Indexes

Adding indexes

Getting indexes

Removing indexes

Saving collections

Save a new collection

Update an existing collection

Deleting collections

Deleting a collection also deletes all its records and associated files.

Collection references

Find all collections that reference a specific collection:

Importing collections

Import collections from configuration data:

Type signature