run · let

total

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

Grup, uni, calcule — nella base di dati, e trae la risposta in lugar de filas.

document databasefree500 results · 30 s
Using Python?

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

Esta è l'azione che sostituisce un loop. Recolhere dez mil ordini per sommar i loro imports è dez mil documenti a travers del filo; la stessa domanda rispondu aquí è una fila.

Parâmetros

collectionstringobrigatório

De qua colezione il oleoducto parte.

pipelineJSON textobrigatório

Una lista non vuota di stadi. Vazio o ausente è negat.

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 }, …]
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}, …]
Il canal è JSON text, e questo è l'onde più importa

Cada nome d'etape inizia con $. Passato come un objeto anidat attraverso un chillante che tira le chiavi, il pipeline arriva vazio de i propri stadi e l'appella non fa nulla per explicarlo.

Due famiglie di stadio sono rifiutate

RefusiPor quê
$where · $funcion · $acumuladorE executano codice dentro la base di dati.
- Usí · - UsíEcriven il risultato in una collezion — che non è un lect.

Ambas sono catturate prima che il oleoducto è enviado, quindi un rejet non costa nulla e non atinge nulla. Scriver un risultato, legîlo e inserire it — che è un scrit, richiesto come un.

I limites

LimiteValor
Results500 — mettere $limite nel pipeline per che scelse 500.
Tempo30 secondi.

Un oleoducto che arrivi al tecto temporale solitamente vuole un $match prima: filtra, poi grup. Agrupare tutto e filtrare poi fa la parte costosa in tot.