# 合计合计

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

`storage.run({ action: "aggregate", collection, pipeline })`

组合、 加入、 计算—— 在数据库中, 并带回答案而不是行 。

Status: document database · free · 500 results · 30 s

这是取代环的动作。 获取一万个单子来加起来, 金额是一万个文件横跨线条; 这里回答的问题是一行 。

## 参数 {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `collection` | string | 必填 | 收集管道的起点 。 |
| `pipeline` | JSON text | 必填 | 空的阶段列表。 拒绝空的或缺席的 。 |

```javascript
await storage.run({
  action: "aggregate",
  collection: "orders",
  pipeline: JSON.stringify([
    { $match: { status: "paid", createdAt: { $gte: "2026-01-01" } } },
    { $group: { _id: "$country", total: { $sum: "$amount" }, orders: { $sum: 1 } } },
    { $sort: { total: -1 } },
    { $limit: 10 },
  ]),
});
// [{ _id: "FR", total: 184200, orders: 912 }, …]
```

> **输油管是 JSON 文本,这是最重要的**
>
> 每个阶段的名字都以美元开头。通过一个电话机作为嵌套对象通过一个连接器,截断了这些钥匙,管道从自己的阶段空空无一人,而电话却毫无用处地失败。

## 两家人拒绝两家人参加 {#refused}

| 被拒绝 | 原因 |
| --- | --- |
| 美元,其中美元 · 职能 · 美元 · 累积美元 | 他们执行数据库内的代码。 |
| 美元 美元 美元 美元 美元 | 他们把结果写成集——这不是读。 |

两者都在输油管发送前就被抓住,所以拒绝就没有任何代价,也无任何结果。要写出结果,读读它, [插入插入](/zh/sdk/ref/connected-storage/run-write/insert) 这是一种书,是被要求的。

## 界限 {#bounds}

| 限制 | 值 |
| --- | --- |
| Results | 500美元,在输油管上设限 所以你选择500美元 |
| 时间时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间 时间  时间 时间  时间  时间  时间   时间   时间   时间   时间   时间  时间 时间    时间  时间   时间   时间                           时间       时间                 时间   时间      时间     时间 时间      时间   时间  时间 时间           时间         时间            时间 | 30秒 30秒 30 seconds. |

达到时间上限的管道通常希望 `$match` 首先:过滤, 然后分组。 组合一切 和过滤之后, 将所有东西都放在成本上。

- [查找查找查找查找查找](/zh/sdk/ref/connected-storage/run/find): 来,文件的保存
- [run()](/zh/sdk/ref/connected-storage/run): 行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动,行动

```python
import json

storage.run(
    action="aggregate",
    collection="orders",
    pipeline=json.dumps([
        {"$match": {"status": "paid", "createdAt": {"$gte": "2026-01-01"}}},
        {"$group": {"_id": "$country", "total": {"$sum": "$amount"}, "orders": {"$sum": 1}}},
        {"$sort": {"total": -1}},
        {"$limit": 10},
    ]),
)
# [{"_id": "FR", "total": 184200, "orders": 912}, …]
```
