Database

Data is organised as collections of documents. A document is any JSON object (≤256 KB). Collection names: letters, numbers, _, -; cannot start with _.

Document shape

{ "id": "k3Jd9…", "data": { …your JSON… }, "owner": "<uid or null>", "createdAt": "2026-09-25 10:00:00", "updatedAt": "…" }

Write

const col = app.db.collection("products");
await col.add({ name: "Tea", price: 250 });          // auto id
await col.add({ name: "Tea" }, "tea-001");           // custom id
await col.doc("tea-001").set({ name: "Green tea", price: 300 });   // replace
await col.doc("tea-001").update({ price: 320 });     // merge (shallow)
await col.doc("tea-001").increment("stock", -1);     // atomic increment
await col.doc("tea-001").update({ note: "hot" }, { views: 1 });   // merge + increment
await col.doc("tea-001").delete();

Read

const d = await col.doc("tea-001").get();      // throws db/not-found if missing
const r = await col.limit(10).get();           // { docs, total, hasMore, empty, first }

Batch

await col.batch([
  { type: "create", data: { name: "A" } },
  { type: "set", id: "x1", data: { name: "B" } },
  { type: "update", id: "x2", data: { done: true }, increment: { n: 1 } },
  { type: "delete", id: "x3" }
]);   // up to 100 ops, single transaction

Ownership

When a signed-in user creates a document, owner is set to their uid automatically. The owner rule level uses it. Servers (secret key) may pass owner explicitly.

Timestamps & ordering

createdAt/updatedAt are server-side strings you can order by. For your own dates, store ISO strings (new Date().toISOString()) so comparisons sort correctly.


Was this page helpful? Tell us. · Download SDK