Parameters
collectionstringrequired*On a document database.
filterJSON textrequired*Which documents. Empty needs all: true.
manybooleanfalse removes a single document. Default: every match.
allbooleanRequired to accept an empty filter.
keystringrequired*On object storage: which object.
// 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")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
// 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)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
The same filter, counted first, tells you what is about to go. It is free, and it is the only preview you get.
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)Deleting works even when the storage is full
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.