Bando Documentation

Documents and relations

Understand the difference between a collection and a document, and learn how to relate documents.

Collection vs. document

This is one of the most important distinctions in Bando.

A collection describes the structure. Adocument is a concrete record of that structure.

CollectionDefines what a post should look like.
DocumentRepresents a specific post.

If the collection is posts, we can have documents such as:

JSON
{
"id": "post-123",
"collection": "posts",
"data": {
"title": "Learning Bando",
"slug": "learning-bando",
"content": "My first article",
"published": true
}
}

Document structure

Bando works with documents that contain information about the record itself and the data defined by the collection.

  • id identifies the document.
  • collection indicates which collection it belongs to.
  • data contains the fields defined by the collection.
  • createdAt indicates when it was created.
  • updatedAt indicates when it was updated.

Relations

A relation allows a document to reference another document.

Imagine that every post has an author. Instead of duplicating all the author's information inside the post, we can store a reference to a document in the authors collection.

TS
author: relation({
collection: "authors",
required: true,
})

The flow can be understood like this:

postsArticle document.
authorReference.
authorsAuthor document.

One relation to multiple documents

When a document can reference multiple documents, usemultiple: true.

TS
reviewers: relation({
collection: "authors",
multiple: true,
})
Manage documents in Studio →
Documents and relations | Bando