Bando Documentation
Collections and fields
Learn how to define the structure of the content your application will store.
What is a collection?
A collection defines the structure of a content type.
If you are familiar with TypeScript, you can initially think of it as a definition that describes which data a particular content type can contain.
In a blog, for example, we might have:
posts
Articles published on the blog.
Articles published on the blog.
authors
People who write the articles.
People who write the articles.
Defining a collection
import { boolean, defineCollection, text } from "bando-cms";
export const posts = defineCollection({
name: "posts",
description: "Blog articles",
fields: {
title: text({ required: true }),
slug: text({ required: true }),
content: text({ required: true }),
published: boolean(),
},
});
Understanding the code
defineCollection() creates the collection definition.
name identifies the collection:
name: "posts"
description explains the purpose of the collection:
description: "Blog articles"
And fields defines the fields that documents in this collection can contain.
Fields
A field is a property of a document.
In our example, a post has a title, slug, content, and publication status.
| Parâmetro | Tipo | Obrigatório | Por omissão | Descrição |
|---|---|---|---|---|
string / text | field | não | — | Field intended for text values. |
boolean | field | não | — | Field representing true or false. |
number | field | não | — | Field intended for numeric values. |
date | field | não | — | Date field. Accepts Date or string. |
relation | field | não | — | Field that stores a reference to another document. |
Required fields
When we write:
title: text({ required: true })
we are saying that a document cannot be created without atitle.