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.
authors
People who write the articles.

Defining a collection

collections/posts.ts
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:

TS
name: "posts"

description explains the purpose of the collection:

TS
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âmetroTipoObrigatórioPor omissãoDescrição
string / textfieldnãoField intended for text values.
booleanfieldnãoField representing true or false.
numberfieldnãoField intended for numeric values.
datefieldnãoDate field. Accepts Date or string.
relationfieldnãoField that stores a reference to another document.

Required fields

When we write:

TS
title: text({ required: true })

we are saying that a document cannot be created without atitle.

Understand documents →
Collections and fields | Bando