> For the complete documentation index, see [llms.txt](https://docs.codemash.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.codemash.io/sdks-and-cli/database/aggregates/save-database-aggregate.md).

# Save Database Aggregate

An **aggregate** is a saved MongoDB aggregation pipeline you can run to compute, group, and summarise data. This method creates the database aggregate and returns its id.

This method is on the **Hub** surface (`norbix.hub.database`) — call it from admin tooling or IaC.

{% hint style="info" %}
These examples assume the SDK is installed and your credentials are set as environment variables — each client reads them automatically, so the constructors below take no arguments. See [Install a Norbix SDK](/sdks-and-cli/install.md).
{% endhint %}

{% tabs %}
{% tab title="JavaScript / TypeScript" %}

```ts
import { Norbix } from '@norbix.ai/ts';
const norbix = new Norbix();

const result = await norbix.hub.database.saveDatabaseAggregate({
  schemaId: 'sch_4kX9mQvR2tYw7ZbC1dFgHj',
  displayName: 'Alice Nguyen',
  pipeline: '[{"$match":{"status":"active"}}]',
  viewId: 'view_4kX9mQvR2tYw7ZbC1dFgHj',
});
```

{% endtab %}

{% tab title=".NET" %}

```csharp
using Norbix.Sdk;
using Norbix.Sdk.Types.Hub;

using var client = new NorbixClient();

var result = await client.Database.SaveDatabaseAggregateAsync(new SaveDatabaseAggregateRequest
{
    SchemaId = "sch_4kX9mQvR2tYw7ZbC1dFgHj",
    DisplayName = "Alice Nguyen",
    Pipeline = "[{\"$match\":{\"status\":\"active\"}}]",
    ViewId = "view_4kX9mQvR2tYw7ZbC1dFgHj",
});
```

{% endtab %}

{% tab title="Python" %}

```python
from norbix_python import NorbixHub

norbix = NorbixHub()

result = norbix.database.save_database_aggregate(
    schemaId="sch_4kX9mQvR2tYw7ZbC1dFgHj",
    displayName="Alice Nguyen",
    pipeline="[{\"$match\":{\"status\":\"active\"}}]",
    viewId="view_4kX9mQvR2tYw7ZbC1dFgHj",
)
```

{% endtab %}

{% tab title="Go" %}

```go
c, _ := norbix.New(norbix.Options{})
ctx := context.Background()

var result map[string]any
err := c.Hub.Database.SaveDatabaseAggregate(ctx, map[string]any{
	"schemaId": "sch_4kX9mQvR2tYw7ZbC1dFgHj",
	"displayName": "Alice Nguyen",
	"pipeline": "[{\"$match\":{\"status\":\"active\"}}]",
	"viewId": "view_4kX9mQvR2tYw7ZbC1dFgHj",
}, &result)
```

{% endtab %}

{% tab title="Dart / Flutter" %}

```dart
import 'package:norbix/norbix_hub.dart';

final hub = NorbixHub();

final result = await hub.database.saveDatabaseAggregate(body: {
  'schemaId': 'sch_4kX9mQvR2tYw7ZbC1dFgHj',
  'displayName': 'Alice Nguyen',
  'pipeline': '[{"$match":{"status":"active"}}]',
  'viewId': 'view_4kX9mQvR2tYw7ZbC1dFgHj',
});
```

{% endtab %}

{% tab title="Swift" %}

```swift
import NorbixSwift

let client = Norbix()

let result = try await client.hub.database.saveDatabaseAggregate([
    "schemaId": "sch_4kX9mQvR2tYw7ZbC1dFgHj",
    "displayName": "Alice Nguyen",
    "pipeline": "[{\"$match\":{\"status\":\"active\"}}]",
    "viewId": "view_4kX9mQvR2tYw7ZbC1dFgHj",
])
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
import dev.norbix.sdk.hub.NorbixHub

val hub = NorbixHub()

val result = hub.database.saveDatabaseAggregate(mapOf(
    "schemaId" to "sch_4kX9mQvR2tYw7ZbC1dFgHj",
    "displayName" to "Alice Nguyen",
    "pipeline" to "[{\"$match\":{\"status\":\"active\"}}]",
    "viewId" to "view_4kX9mQvR2tYw7ZbC1dFgHj",
))
```

{% endtab %}

{% tab title="CLI" %}

```sh
norbix hub db aggregate save --schemaId sch_4kX9mQvR2tYw7ZbC1dFgHj --displayName 'Alice Nguyen' --pipeline '[{"$match":{"status":"active"}}]' --viewId view_4kX9mQvR2tYw7ZbC1dFgHj
```

{% endtab %}
{% endtabs %}

## In the dashboard

Manage this visually in Norbix Cloud — see [Database → Aggregates](/norbix-cloud/database/aggregation.md).

## API reference

Full request and response for this endpoint: [Save Database Aggregate](/api-reference/database/aggregates/save-database-aggregate.md).
