运行 $ 写

插入插入

storage.run({ action: "insert", collection, documents })

将文档添加到收藏中。 一次1到500个文件。

document databasefree1 to 500
Using Python?

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

参数

collectionstring必填

哪个收藏

documentsJSON text必填

1至500份文件的清单。 拒绝在该范围以外 。

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": ["…", "…"]}

500多

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"]
批量不是交易

如果在循环中打的电话失败, 则在它着陆之前的电话已经着陆。 保持计数, 并使操作可重复进行 。 给每个文档一个您自己的识别符, 使用时要保存, 如果运行两次, 操作不能重复 。

空格满时拒绝

quota_exceeded,在写前检查。删除仍然工作超过配额,这样你就可以腾出空间,读 使用 而不是在半途发现