Bando Documentation

findById(), create(), update() and delete()

Read, create, update, and delete documents.

What is a mutation?

A mutation is an operation that changes data.

The TypeScript client has four main operations:

findById()
Reads a specific document.
create()
Creates a document.
update()
Updates a document.
delete()
Deletes a document.
TS
import { bando } from "@/lib/bando";
import type { Post } from "@/types/post";
const posts = bando.collection<Post>("posts");
const post = await posts.findById("document-id");
await posts.create({
title: "Hello",
slug: "hello",
content: "…",
published: false,
});
await posts.update("document-id", {
published: true,
});
await posts.delete("document-id");

findById()

Finds a document by its ID.

TS
const post = await posts.findById("document-id");

When the document does not exist, findById() returnsnull.

create()

Creates a new document using the fields defined by the collection.

update()

Updates an existing document.

delete()

Deletes a document.

The methods, except findById() when the document is not found, reject the Promise when the API returns an error.create() and update() return the resulting document.

findById(), create(), update() and delete() | Bando