# count

Canonical URL: https://developers.iagenify.com/sdk/ref/connected-storage/run/count/
Language: en

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

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

Status: document database · free · 30 s ceiling

```javascript
await storage.run({ action: "count", collection: "orders",
  filter: JSON.stringify({ status: "paid" }) });
// { count: 8412 }
```

## Why not find and count the result {#why}

|  | 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 {#timeout}

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 {#estimate}

For « roughly how big is this », [collections](/sdk/ref/connected-storage/run/collections) gives a figure from metadata without reading anything. Use `count` when the number drives a decision.

- [find](/sdk/ref/connected-storage/run/find): Les documents eux-mêmes.
- [run()](/sdk/ref/connected-storage/run): Toutes les actions, les garde-fous et ce que chacune coûte.

```python
import json

storage.run(action="count", collection="orders",
            filter=json.dumps({"status": "paid"}))
# {"count": 8412}
```
