> ## Documentation Index
> Fetch the complete documentation index at: https://docs.doglytdc.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Collections (script database)

> Declare collections and access rules, and use the database inside functions.

Collections are the script's database. You declare the collections and who can read and write in `supabase/collections.json`.

## collections.json

```json theme={null}
{
  "collections": {
    "notas": { "read": "users", "write": "users" },
    "placar": { "read": "public", "write": "owner" }
  }
}
```

| Rule | Who is allowed |
| - | - |
| `owner` | Only the script owner (default when not specified) |
| `users` | Anyone logged in to DoglyTdc |
| `public` | Anyone, even without logging in |

Limits: up to 20 collections; names with lowercase letters, numbers, `_` and `-`, up to 40 characters. The file is read when the backend is deployed. If it contains an error, the previous collections remain and the error appears in the deployment summary.

## Use inside a function

```js theme={null}
function handler(request) {
  const notas = doglytdc.db.collection("notas");
  const nova = notas.insert({ texto: "Oi" });
  const lista = notas.list({ limit: 20, order: "desc", where: { texto: "Oi" } });
  const total = notas.count({ texto: "Oi" });
  return doglytdc.respond(200, { nova, lista, total });
}
```

| Method | What it does |
| - | - |
| `get(id)` | One document, or `null` |
| `list({ limit, offset, order, where })` | Lists documents. `limit` from 1 to 100 (default 20), `offset` up to 10,000, `order` `asc` or `desc` (default `desc`, by creation date), `where` with up to 10 equality fields |
| `count(where)` | Number of documents |
| `insert(data)` | Creates a document |
| `update(id, data)` | Replaces the data |
| `delete(id)` | Deletes |

## Document format

```json theme={null}
{
  "id": "e1f2a3b4-c5d6-4e7f-8a9b-0c1d2e3f4a5b",
  "data": { "texto": "Oi" },
  "created_at": "2026-11-06T12:00:00Z",
  "updated_at": "2026-11-06T12:00:00Z",
  "mine": true
}
```

`mine` indicates whether the caller created the document. The document never shows who created it.

## Important rules

* The document must be an object and no larger than **64 KB**.
* Up to **10,000 documents** per collection.
* `update` and `delete` only work for **the document's creator** or the script owner, even if the write rule is `users` or `public`.

Possible errors: "Collection … does not exist in supabase/collections.json.", "No permission to read/write in …", "Document not found.", "Document too large (max. 64 KB).", "Limit of 10000 documents per collection.", "Only the document's creator (or the script owner) can modify it."

## Through the API

The same collections and rules apply in the API: see [Collections and documents](https://docs.doglytdc.dev/en/scripts/api-reference/collections.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.