# 删除删除删除

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

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

从桶中删除匹配的文档或对象。默认情况下,每个匹配都匹配,这是这里值得知道的一个默认。

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

## 参数 {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `collection` | string | 必填* | 文件数据库。 |
| `filter` | JSON text | 必填* | 文档。空需要 `all: true`. |
| `many` | boolean |  | `false` 删除单个文档。默认:每个匹配。 |
| `all` | boolean |  | 需要接受空过滤器 。 |
| `key` | string | 必填* | 物体储存:哪个物体。 |

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

> **此一个默认默认为每次匹配, 与更新不同**
>
> 更新一个, 除非您说很多: 确实; 删除全部删除, 除非您说很多: 假 。 两种默认情况不同, 不同之处无法从一个方向恢复 。

## 拒绝一个空过滤器 {#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 });
```

警卫在任何信息到达数据库之前,在要求特工批准之前,即不需要任何人的判断,就停止危险形状。

## 删除前的计数 {#count-first}

同一个过滤器, 计数先, 告诉您即将要做什么 。 它是免费的, 这是您唯一能预览的 。

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

## 即使在存储器满满时也可删除工作 {#quota}

拒绝写入超过配额; 删除不是。 这就是你制造空间的方式—— 存储无法空, 因为满满将是一个陷阱 。

- [数数](/zh/sdk/ref/connected-storage/run/count): Voir ce que le filtre touche, avant.
- [run()](/zh/sdk/ref/connected-storage/run): 行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动

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