Bando Documentation

findMany()

Query documents and receive the results together with the total count.

Querying content

After creating documents, the next task is retrieving them in your application.

Bando lets you combine filters, pagination, and sorting in a single query.

A real example

Imagine we want the 10 most recently published posts:

TS
const { data, total } =
await bando.collection<Post>("posts").findMany({
limit: 10,
offset: 0,
sort: "-createdAt",
filters: {
published: true,
},
});

What do we receive?

The result contains two important pieces of information:

TS
const { data, total } = result;

data contains the documents found.

total contains the total number of documents matching the query, allowing you to build pagination into the interface.

Pagination

limit defines how many documents we want to receive.offset defines how many documents should be skipped before results start being returned.

For example, to fetch the first 10:

TS
{
limit: 10,
offset: 0,
}

To fetch the next 10:

TS
{
limit: 10,
offset: 10,
}

Sorting

Sorting accepts id, createdAt, andupdatedAt.

A - before the field means descending order:

TS
sort: "-createdAt"

Filters

Current filters use equality.

TS
filters: {
published: true,
}

This searches for documents whose published field is true.

ParâmetroTipoObrigatórioPor omissãoDescrição
limitintegernãoMaximum number of documents returned. Must be a non-negative integer.
offsetintegernão0Number of documents skipped before results start being returned.
sortstringnão-createdAtField used to sort results. Accepts id, createdAt, or updatedAt. The - prefix indicates descending order.
fieldstringnãoEquality filter. For example, published=true searches for documents whose published field is true.
Learn about mutations →
Learn about the TypeScript client →
findMany() | Bando