# Aggregate

When you have a complex query where you need to link more than several collections together, and when you need to calculate, aggregate, sum up, and group the data, you can write aggregate and execute it from the API.

{% openapi src="<https://760328771-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LwSkuCpTNI_AerL8J2a%2Fuploads%2FCpzJktmKXD6FMPSah1nK%2Fopenapi.json?alt=media&token=854cdd6a-61b2-49a5-99f4-6bc091e5c3d6>" path="/{version}/db/{CollectionName}/aggregate/{id}" method="get" %}
[openapi.json](https://760328771-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LwSkuCpTNI_AerL8J2a%2Fuploads%2FCpzJktmKXD6FMPSah1nK%2Fopenapi.json?alt=media\&token=854cdd6a-61b2-49a5-99f4-6bc091e5c3d6)
{% endopenapi %}

{% openapi src="<https://760328771-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LwSkuCpTNI_AerL8J2a%2Fuploads%2FCpzJktmKXD6FMPSah1nK%2Fopenapi.json?alt=media&token=854cdd6a-61b2-49a5-99f4-6bc091e5c3d6>" path="/{version}/db/{CollectionName}/aggregate/{id}" method="post" expanded="true" %}
[openapi.json](https://760328771-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LwSkuCpTNI_AerL8J2a%2Fuploads%2FCpzJktmKXD6FMPSah1nK%2Fopenapi.json?alt=media\&token=854cdd6a-61b2-49a5-99f4-6bc091e5c3d6)
{% endopenapi %}

{% tabs %}
{% tab title=".NET" %}

```csharp
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);

var aggregateOptions = new AggregateOptions {
    Tokens = new Dictionary<string, string> { { "name", "John" } }
}

var aggregateResult = await service.AggregateAsync<PersonProjection>(
    Guid.Parse("{AGGREGATE_ID}"),
    aggregateOptions
);
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Check the docs on [aggregation](https://docs.codemash.io/dashboard/database/aggregation).
{% endhint %}
