await storage.run({ action: "createCollection", collection: "invoices" });
// { ok: true, created: "invoices" }storage.run(action="createCollection", collection="invoices")
# {"ok": True, "created": "invoices"}When you actually need it
An insert into a name no collection carries yet creates it. So this is for the cases where the structure must exist before anything is written: a setup step, a migration, an interface that lists collections before there is data.
An existing name is refused, with a readable message
Rather than the database's own code, which names a condition without saying what to do. If creating twice is harmless for you, treat the refusal as success.
async function ensureCollection(storage, collection) {
const existing = await storage.run({ action: "collections" });
if (existing.some((c) => c.name === collection)) return "already there";
await storage.run({ action: "createCollection", collection });
return "created";
}def ensure_collection(storage, collection):
existing = storage.run(action="collections")
if any(c["name"] == collection for c in existing):
return "already there"
storage.run(action="createCollection", collection=collection)
return "created"It is a write, and it is asked for as one
Structural changes are in the same permission category as data ones — an agent is asked before creating a collection, in every mode but the most open. See the storage category.