# createCollection

Canonical URL: https://developers.iagenify.com/sdk/ref/connected-storage/run-write/create-collection/
Language: en

`storage.run({ action: "createCollection", collection })`

Creates an empty collection. Rarely needed — writing to a name creates it — but explicit when the structure is the point.

Status: document database · free · refuses a duplicate

```javascript
await storage.run({ action: "createCollection", collection: "invoices" });
// { ok: true, created: "invoices" }
```

## When you actually need it {#needed}

An [insert](/sdk/ref/connected-storage/run-write/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 {#exists}

> **The refusal says the collection already exists**
>
> 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.

```javascript
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";
}
```

## It is a write, and it is asked for as one {#permission}

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](/sdk/agent/permissions/categories/storage).

- [dropCollection](/sdk/ref/connected-storage/run-write/drop-collection): L'inverse, et ce qu'il emporte.
- [run()](/sdk/ref/connected-storage/run): Toutes les actions, les garde-fous et ce que chacune coûte.

```python
storage.run(action="createCollection", collection="invoices")
# {"ok": True, "created": "invoices"}
```

```python
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"
```
