# delete

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

`storage.run({ action: "delete", collection, filter, many, all })`

Removes documents that match — or an object from a bucket. Every match by default, which is the one default worth knowing here.

Status: document database · object storage · free · all matches by default

## Parameters {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `collection` | string | required* | On a document database. |
| `filter` | JSON text | required* | Which documents. Empty needs `all: true`. |
| `many` | boolean |  | `false` removes a single document. Default: every match. |
| `all` | boolean |  | Required to accept an empty filter. |
| `key` | string | required* | On object storage: which object. |

```javascript
// Documents
await storage.run({ action: "delete", collection: "sessions",
  filter: JSON.stringify({ expiresAt: { $lt: new Date().toISOString() } }) });
// { ok: true, deletedCount: 142 }

// An object
await storage.run({ action: "delete", key: "invoices/2026/01/a.pdf" });
```

> **This one defaults to every match, unlike update**
>
> update touches one unless you say many: true; delete removes all of them unless you say many: false. The two defaults differ, and the difference is not recoverable in one direction.

## An empty filter is refused {#empty}

```javascript
// Refused: this would empty the collection
await storage.run({ action: "delete", collection: "logs", filter: JSON.stringify({}) });

// Accepted: you said so, explicitly
await storage.run({ action: "delete", collection: "logs",
  filter: JSON.stringify({}), all: true });
```

The guard runs before anything reaches the database, and before an agent is asked for permission — so the dangerous shape is stopped without needing anyone's judgement.

## Count before you delete {#count-first}

The same filter, counted first, tells you what is about to go. It is free, and it is the only preview you get.

```javascript
const { count } = await storage.run({ action: "count", collection, filter });
if (count > 1000) throw new Error(`that filter matches ${count} documents — check it`);

await storage.run({ action: "delete", collection, filter });
```

## Deleting works even when the storage is full {#quota}

Writes are refused past the quota; deletes are not. That is how you make room — a storage you cannot empty because it is full would be a trap.

- [count](/sdk/ref/connected-storage/run/count): Voir ce que le filtre touche, avant.
- [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

# Documents
storage.run(action="delete", collection="sessions",
            filter=json.dumps({"expiresAt": {"$lt": datetime.now(timezone.utc).isoformat()}}))
# {"ok": True, "deletedCount": 142}

# An object
storage.run(action="delete", key="invoices/2026/01/a.pdf")
```

```python
import json

# Refused: this would empty the collection
storage.run(action="delete", collection="logs", filter=json.dumps({}))

# Accepted: you said so, explicitly
storage.run(action="delete", collection="logs", filter=json.dumps({}), all=True)
```

```python
count = storage.run(action="count", collection=collection, filter=filter)["count"]
if count > 1000:
    raise ValueError(f"that filter matches {count} documents — check it")

storage.run(action="delete", collection=collection, filter=filter)
```
