# dropCollection

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

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

Removes a collection and everything in it. It tells you how many documents went.

Status: document database · free · not reversible

```javascript
await storage.run({ action: "dropCollection", collection: "temp_import" });
// { ok: true, dropped: "temp_import", documents: 48211 }
```

> **documents is how many you just destroyed**
>
> It comes back after the fact, not before. Read the count yourself first if the number would have changed your mind — that call is free.

```javascript
const { count } = await storage.run({ action: "count", collection });
if (count > 0) throw new Error(`${collection} still holds ${count} documents`);

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

## A collection that is not there is refused {#missing}

Rather than answering « done » for something that never existed — which would hide a typo in a name, at the exact moment a typo matters most.

```javascript
const existing = await storage.run({ action: "collections" });
if (!existing.some((c) => c.name === collection)) {
  // Nothing to drop. A misspelling here would otherwise look like success.
}
```

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

Like [delete](/sdk/ref/connected-storage/run-write/delete), dropping is allowed past the quota: it is how you make room, so refusing it would leave a storage that cannot be emptied.

## What an agent may do with it {#agent}

> **The most open mode is the only one that lets this through unasked**
>
> In the planning mode it is refused outright. Everywhere else it is asked for. If an agent of yours should never drop anything, say so in its instructions and answer the prompt — the mode alone is a blunt instrument.

- [La catégorie storage](/sdk/agent/permissions/categories/storage): Ce qu'un mode laisse passer, et ce qu'il demande.
- [run()](/sdk/ref/connected-storage/run): Toutes les actions, les garde-fous et ce que chacune coûte.

```python
storage.run(action="dropCollection", collection="temp_import")
# {"ok": True, "dropped": "temp_import", "documents": 48211}
```

```python
count = storage.run(action="count", collection=collection)["count"]
if count > 0:
    raise RuntimeError(f"{collection} still holds {count} documents")

storage.run(action="dropCollection", collection=collection)
```

```python
existing = storage.run(action="collections")
if not any(c["name"] == collection for c in existing):
    pass  # Nothing to drop. A misspelling here would otherwise look like success.
```
