# insert

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

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

Adds documents to a collection. One to five hundred at a time.

Status: document database · free · 1 to 500

## Parameters {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `collection` | string | required | Which collection. |
| `documents` | JSON text | required | A list of 1 to 500 documents. Outside that range is refused. |

```javascript
await storage.run({
  action: "insert",
  collection: "events",
  documents: JSON.stringify([
    { type: "signup", at: new Date().toISOString() },
    { type: "signup", at: new Date().toISOString() },
  ]),
});
// { insertedCount: 2, insertedIds: ["…", "…"] }
```

## More than five hundred {#batches}

```javascript
const SIZE = 500;
let inserted = 0;

for (let i = 0; i < all.length; i += SIZE) {
  const batch = all.slice(i, i + SIZE);
  const res = await storage.run({ action: "insert", collection,
    documents: JSON.stringify(batch) });
  inserted += res.insertedCount;
}
```

> **A batch is not a transaction**
>
> If one call in the loop fails, the ones before it have landed. Keep the count, and make the operation repeatable — give each document an identifier of your own and use save instead, if running twice must not duplicate.

## It is refused when the space is full {#quota}

`quota_exceeded`, and it is checked before the write. Deleting still works past the quota, so you can make room — read [usage](/sdk/ref/connected-storage/run/usage) before a large import rather than discovering it halfway.

- [save](/sdk/ref/connected-storage/run-write/save): Insérer ou remplacer, selon l'identité.
- [run()](/sdk/ref/connected-storage/run): Toutes les actions, les garde-fous et ce que chacune coûte.

```python
import json
from datetime import datetime, timezone

now = datetime.now(timezone.utc).isoformat()
storage.run(
    action="insert",
    collection="events",
    documents=json.dumps([
        {"type": "signup", "at": now},
        {"type": "signup", "at": now},
    ]),
)
# {"insertedCount": 2, "insertedIds": ["…", "…"]}
```

```python
import json

SIZE = 500
inserted = 0

for i in range(0, len(rows), SIZE):
    batch = rows[i:i + SIZE]
    res = storage.run(action="insert", collection=collection, documents=json.dumps(batch))
    inserted += res["insertedCount"]
```
