await storage.run({ action: "count", collection: "orders",
filter: JSON.stringify({ status: "paid" }) });
// { count: 8412 }import json
storage.run(action="count", collection="orders",
filter=json.dumps({"status": "paid"}))
# {"count": 8412}Why not find and count the result
| count | find then .length | |
|---|---|---|
| Sent back | One number | Every matching document |
| Cost to you | Nothing | Nothing — but the time and memory are real |
| Correct above the limit | yes | no — a limit caps the number, with nothing to say it did |
Counting a find result is wrong as soon as there is a limit
The length you measure is the page, not the total. That mistake does not fail — it returns a plausible smaller number, which is worse.
It gives up after thirty seconds
A count over a large collection without a usable index can run long; the ceiling makes it fail rather than hang. When you hit it, the answer is an index on the field you filter by — not a retry.
When the estimate is enough
For « roughly how big is this », collections gives a figure from metadata without reading anything. Use count when the number drives a decision.