# -Supprimer

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

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

Elimina i documenti che coincide — o un objeto de un cubo. Ogni coincident per default, che è il predefault vale la pena sabiîne qui.

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

## Parâmetros {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `collection` | string | obrigatório* | Su una base de dadi documenta. |
| `filter` | JSON text | obrigatório* | Quali documenti. Necessita vat `all: true`. |
| `many` | boolean |  | `false` elimina un solo documento. Predefinito: ogni match. |
| `all` | boolean |  | Obligatoriu di accettare un filtro vuoto. |
| `key` | string | obrigatório* | Sobre l'ogget de stoccatura: qual ogget. |

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

> **Questo predefinit a ogni match, a disprese de update**
>
> Update tocca uno a meno che si dice molti: true; cancella elimina tutti loro a meno che si dice molti: false. I due predefiniti differen, e la differenza non è recuperabile in una direzion.

## Un filtro vazio è negat {#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 });
```

La guardia vara prima che nulla arrivi alla base di dati, e prima che un agente è chiesto permesse — per cui la forma pericolosa è interrotta senza necessitare di giudizio di ningun.

## Conta prima di cancellare {#count-first}

Il medesimo filtro, contat prima, ti dice ce che sta per partir. È gratis, ed è la sola vista preliminare che si obtiene.

```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 });
```

## La cancellazione funziona anche quando il stoccaggio è pieno {#quota}

I scrivis sono respintos al dispass la quota; eliminas no lo sono. Issí è como se fa spazio — un storage non si può vaciare perché è pieno sarebbe un cappuccio.

- [conta](/pt/sdk/ref/connected-storage/run/count): Veder ce que le filtre touche, avant.
- [run()](/pt/sdk/ref/connected-storage/run): Tutes les actions, les garde-fous et ce que chaque coute.

```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)
```
