运行 $ 写

删除删除删除

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

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

document database · object storagefreeall matches by default
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

参数

collectionstring必填*

文件数据库。

filterJSON text必填*

文档。空需要 all: true.

manyboolean

false 删除单个文档。默认:每个匹配。

allboolean

需要接受空过滤器 。

keystring必填*

物体储存:哪个物体。

// 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" });
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")
此一个默认默认为每次匹配, 与更新不同

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

拒绝一个空过滤器

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

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

删除前的计数

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

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

即使在存储器满满时也可删除工作

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