Parameters
collectionstringrequiredWhich collection.
documentsJSON textrequiredA list of 1 to 500 documents. Outside that range is refused.
await storage.run({
action: "insert",
collection: "events",
documents: JSON.stringify([
{ type: "signup", at: new Date().toISOString() },
{ type: "signup", at: new Date().toISOString() },
]),
});
// { insertedCount: 2, insertedIds: ["…", "…"] }import json
from datetime import datetime, timezone
now = datetime.now(timezone.utc).isoformat()
storage.run(
action="insert",
collection="events",
documents=json.dumps([
{"type": "signup", "at": now},
{"type": "signup", "at": now},
]),
)
# {"insertedCount": 2, "insertedIds": ["…", "…"]}More than five hundred
const SIZE = 500;
let inserted = 0;
for (let i = 0; i < all.length; i += SIZE) {
const batch = all.slice(i, i + SIZE);
const res = await storage.run({ action: "insert", collection,
documents: JSON.stringify(batch) });
inserted += res.insertedCount;
}import json
SIZE = 500
inserted = 0
for i in range(0, len(rows), SIZE):
batch = rows[i:i + SIZE]
res = storage.run(action="insert", collection=collection, documents=json.dumps(batch))
inserted += res["insertedCount"]A batch is not a transaction
If one call in the loop fails, the ones before it have landed. Keep the count, and make the operation repeatable — give each document an identifier of your own and use save instead, if running twice must not duplicate.
It is refused when the space is full
quota_exceeded, and it is checked before the write. Deleting still works past the quota, so you can make room — read usage before a large import rather than discovering it halfway.