Collection Configs
A Collection is a group of records, called Documents, that all share a common schema. You can define as many Collections as your application needs. Each Document in a Collection is stored in the Database based on the Fields that you define, and automatically generates a Local API, REST API, and GraphQL API used to manage your Documents.
Collections are also used to achieve Authentication in Payload. By defining a Collection with auth
options, that Collection receives additional operations to support user authentication.
Collections are the primary way to structure recurring data in your application, such as users, products, pages, posts, and other types of content that you might want to manage. Each Collection can have its own unique Access Control, Hooks, Admin Options, and more.
To define a Collection Config, use the collection
property in your Payload Config:
Config Options
It's often best practice to write your Collections in separate files and then import them into the main Payload Config.
Here is what a simple Collection Config might look like:
The following options are available:
Option | Description |
---|---|
| The configuration options for the Admin Panel. More details. |
| Provide Access Control functions to define exactly who should be able to do what with Documents in this Collection. More details. |
| Specify options if you would like this Collection to feature authentication. More details. |
| Extension point for adding custom data (e.g. for plugins) |
| When true, do not show the "Duplicate" button while editing documents within this Collection and prevent |
| Pass a top-level field to sort by default in the Collection List View. Prefix the name of the field with a minus symbol ("-") to sort in descending order. Multiple fields can be specified by using a string array. |
| Custom table or Collection name depending on the Database Adapter. Auto-generated from slug if not defined. |
| Add custom routes to the REST API. Set to |
| Array of field types that will determine the structure and functionality of the data stored within this Collection. More details. |
| Manage GraphQL-related properties for this collection. More |
| Entry point for Hooks. More details. |
| Singular and plural labels for use in identifying this Collection throughout Payload. Auto-generated from slug if not defined. |
| Enables or disables document locking. By default, document locking is enabled. Set to an object to configure, or set to |
| Unique, URL-friendly string that will act as an identifier for this Collection. |
| Set to false to disable documents' automatically generated |
| An object with property |
| Specify options if you would like this Collection to support file uploads. For more, consult the Uploads documentation. |
| Set to true to enable default options, or configure with object properties. More details. |
| Specify which fields to select when this Collection is populated from another document. More Details. |
* An asterisk denotes that a property is required.
Fields
Fields define the schema of the Documents within a Collection. To learn more, go to the Fields documentation.
Access Control
Collection Access Control determines what a user can and cannot do with any given Document within a Collection. To learn more, go to the Access Control documentation.
Hooks
Collection Hooks allow you to tie into the lifecycle of your Documents so you can execute your own logic during specific events. To learn more, go to the Hooks documentation.
Admin Options
The behavior of Collections within the Admin Panel can be fully customized to fit the needs of your application. This includes grouping or hiding their navigation links, adding Custom Components, selecting which fields to display in the List View, and more.
To configure Admin Options for Collections, use the admin
property in your Collection Config:
The following options are available:
Option | Description |
---|---|
| Text or localization object used to group Collection and Global links in the admin navigation. Set to |
| Set to true or a function, called with the current user, returning true to exclude this Collection from navigation and admin routing. |
| Admin-specific hooks for this Collection. More details. |
| Specify a top-level field to use for a document title throughout the Admin Panel. If no field is defined, the ID of the document is used as the title. A field with |
| Text to display below the Collection label in the List View to give editors more information. Alternatively, you can use the |
| Array of field names that correspond to which columns to show by default in this Collection's List View. |
| Hides the "API URL" meta field while editing documents within this Collection. |
| The Rich Text field features a |
| The Rich Text field features a |
| Page metadata overrides to apply to this Collection within the Admin Panel. More details. |
| Function to generate preview URLs within the Admin Panel that can point to your app. More details. |
| Enable real-time editing for instant visual feedback of your front-end application. More details. |
| Swap in your own React components to be used within this Collection. More details. |
| Specify which fields should be searched in the List search view. More details. |
| Set pagination-specific options for this Collection. More details. |
| You can define a default base filter for this collection's List view, which will be merged into any filters that the user performs. |
Custom Components
Collections can set their own Custom Components which only apply to Collection-specific UI within the Admin Panel. This includes elements such as the Save Button, or entire layouts such as the Edit View.
To override Collection Components, use the admin.components
property in your Collection Config:
The following options are available:
Option | Description |
---|---|
| An array of components to inject after the built-in List View. More details. |
| An array of components to inject after the built-in List View's table. More details. |
| An array of components to inject before the built-in List View. More details. |
| An array of components to inject before the built-in List View's table. More details. |
| An array of components to render within a menu next to the List Controls (after the Columns and Filters options) |
| A component to render below the Collection label in the List View. An alternative to the |
| Override specific components within the Edit View. More details. |
| Override or create new views within the Admin Panel. More details. |
Edit View Options
The following options are available:
Option | Description |
---|---|
| Replace the default Save Button within the Edit View. Drafts must be disabled. More details. |
| Replace the default Save Draft Button within the Edit View. Drafts must be enabled and autosave must be disabled. More details. |
| Replace the default Publish Button within the Edit View. Drafts must be enabled. More details. |
| Replace the default Preview Button within the Edit View. Preview must be enabled. More details. |
| Replace the default Upload component within the Edit View. Upload must be enabled. More details. |
Pagination
All Collections receive their own List View which displays a paginated list of documents that can be sorted and filtered. The pagination behavior of the List View can be customized on a per-Collection basis, and uses the same Pagination API that Payload provides.
To configure pagination options, use the admin.pagination
property in your Collection Config:
The following options are available:
Option | Description |
---|---|
| Integer that specifies the default per-page limit that should be used. Defaults to 10. |
| Provide an array of integers to use as per-page options for admins to choose from in the List View. |
List Searchable Fields
In the List View, there is a "search" box that allows you to quickly find a document through a simple text search. By default, it searches on the ID field. If defined, the admin.useAsTitle
field is used. Or, you can explicitly define which fields to search based on the needs of your application.
To define which fields should be searched, use the admin.listSearchableFields
property in your Collection Config:
GraphQL
You can completely disable GraphQL for this collection by passing graphQL: false
to your collection config. This will completely disable all queries, mutations, and types from appearing in your GraphQL schema.
You can also pass an object to the collection's graphQL
property, which allows you to define the following properties:
Option | Description |
---|---|
| Override the "singular" name that will be used in GraphQL schema generation. |
| Override the "plural" name that will be used in GraphQL schema generation. |
| Disable all GraphQL queries that correspond to this collection by passing |
| Disable all GraphQL mutations that correspond to this collection by passing |
TypeScript
You can import types from Payload to help make writing your Collection configs easier and type-safe. There are two main types that represent the Collection Config, CollectionConfig
and SanitizeCollectionConfig
.
The CollectionConfig
type represents a raw Collection Config in its full form, where only the bare minimum properties are marked as required. The SanitizedCollectionConfig
type represents a Collection Config after it has been fully sanitized. Generally, this is only used internally by Payload.