run · read

count

storage.run({ action: "count", collection, filter })

How many documents match. The cheap way to ask a question whose answer is a number.

document databasefree30 s ceiling
Using Python?

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

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

countfind then .length
Sent backOne numberEvery matching document
Cost to youNothingNothing — but the time and memory are real
Correct above the limityesno — 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.