> For the complete documentation index, see [llms.txt](https://codemash.gitbook.io/codemash/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codemash.gitbook.io/codemash/api-reference/database/collections/hub-records.md).

# Hub record endpoints

The record endpoints of the Hub (developer / admin plane) — same routes as the data API, for developer keys and AI tools.

The **Hub** serves the same record operations as the data-plane [Collections](/codemash/api-reference/database/collections.md) endpoints, on the same paths, for developer and admin callers: Cloud, scripts with a project API key, the CLI and AI tools. Your app normally calls the **API** host; use the Hub routes when you work on the project as a developer. Two Hub-only record endpoints sit next to them: [Seed Collection Records](/codemash/api-reference/database/collections/seed-collection-records.md) and [Get Collection Indexes](/codemash/api-reference/database/collections/get-collection-indexes.md). `findOwn` exists only on the API.

| Operation             | Route                                                                 | Hub request (SDK method)     | AI tool                        |
| --------------------- | --------------------------------------------------------------------- | ---------------------------- | ------------------------------ |
| Find                  | `GET /collections/{collectionName}`                                   | `FindRecords`                | `find_records`                 |
| Find One              | `GET /collections/{collectionName}/{id}`                              | `FindOneRecord`              | `find_one_record`              |
| Count                 | `GET /collections/{collectionName}/count`                             | `CountRecords`               | `count_records`                |
| Distinct              | `GET /collections/{collectionName}/distinct`                          | `DistinctRecordValues`       | `distinct_record_values`       |
| Aggregate             | `POST /collections/{collectionName}/aggregate`                        | `AggregateRecords`           | `aggregate_records`            |
| Execute Aggregate     | `POST /collections/{collectionName}/aggregates/{aggregateId}/execute` | `ExecuteRecordsAggregate`    | `execute_records_aggregate`    |
| Insert One            | `POST /collections/{collectionName}`                                  | `InsertRecord`               | `insert_record`                |
| Insert Many           | `POST /collections/{collectionName}/many`                             | `InsertManyRecords`          | `insert_many_records`          |
| Update One            | `PUT /collections/{collectionName}/{id}`                              | `UpdateOneRecord`            | `update_one_record`            |
| Update Many           | `PUT /collections/{collectionName}/many`                              | `UpdateManyRecords`          | `update_many_records`          |
| Replace One           | `PUT /collections/{collectionName}/{id}/replace`                      | `ReplaceRecord`              | `replace_record`               |
| Delete One            | `DELETE /collections/{collectionName}/{id}`                           | `DeleteRecord`               | `delete_record`                |
| Delete Many           | `DELETE /collections/{collectionName}/many`                           | `DeleteManyRecords`          | `delete_many_records`          |
| Change Responsibility | `PUT /collections/{collectionName}/{id}/responsibility`               | `ChangeRecordResponsibility` | `change_record_responsibility` |

Rules that hold on both hosts:

* `filter`, `document`, `update` and `pipeline` are JSON **strings**.
* `updateOne` / `updateMany` take the bare fields to change (the server applies them with `$set`) and are validated against the published schema like inserts; a value the schema forbids is refused.
* A filter or pipeline with `$where`, `$function` or `$accumulator`, or a read pipeline with `$out` / `$merge`, is refused with `CM-ERRORS-DATABASE-031` (one error per operator, at any depth).
* Without `databaseIntegrationId` the default integration of the request's environment is used.
* **Bulk writes need a real filter.** `Update Many` and `Delete Many` refuse an empty filter `{}` (or no filter) with `CM-ERRORS-DATABASE-037`. To change or delete every record on purpose, send `allRecords: true` (`AllRecords` in .NET) with the empty filter.
* **Soft-deleted records are not written.** Update One / Update Many / Replace One / Change Responsibility skip records that are soft-deleted — for a write they are "not found", just as reads do not return them.
* **Updates take bare fields only.** An update body with MongoDB operators at the top level (`{"$inc": {"stock": 1}}`, `$set`, `$unset`, …) is refused with `CM-ERRORS-DATABASE-035`, one error per operator. Send `{"stock": 5}`; the server applies it with `$set`.
* **A broken record body has its own error.** A `document` / `replacement` that is not a JSON object (or an Insert Many item that is not an object) answers `CM-ERRORS-DATABASE-036`, with the index of the bad item; `CM-ERRORS-DATABASE-005` is only for a broken filter.
* **Own scope works for bulk operations.** A caller with only own-record rights may call Insert Many (`createAsUser` — every record gets the caller as owner, even if the document names someone else), Update Many (`updateOwn`) and Delete Many (`deleteOwn`) — the filter is narrowed to the caller's own records. Changing the owner in an own-scope Update Many is refused (that needs full `database:update`).
* **The new owner must be a project user.** Change Responsibility checks the new owner in the users of the environment's default database integration and answers `CM-ERRORS-MEMBERSHIP-USERS-012` when there is no such user — nothing is written.

Permissions: `database:read` / `create` / `update` / `delete` on the collection (`database:collection:<name>`).

### Find

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}" method="get" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

### Find One

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}/{id}" method="get" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

### Count

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}/count" method="get" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

### Distinct

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}/distinct" method="get" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

### Aggregate

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}/aggregate" method="post" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

### Execute Aggregate

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}/aggregates/{aggregateId}/execute" method="post" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

### Insert One

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}" method="post" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

### Insert Many

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}/many" method="post" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

### Update One

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}/{id}" method="put" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

### Update Many

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}/many" method="put" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

### Replace One

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}/{id}/replace" method="put" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

### Delete One

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}/{id}" method="delete" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

### Delete Many

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}/many" method="delete" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

### Change Responsibility

{% openapi src="/files/0gOkqzp7kyziG9XPpCBy" path="/{version}/database/collections/{collectionName}/{id}/responsibility" method="put" %}
[norbix-hub-swagger.json](https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-7c7445e68689b62620e59cb01a3523deb46b865b%2Fnorbix-hub-swagger.json?alt=media)
{% endopenapi %}

## In Cloud

[Records](/codemash/cloud/database/collections/records.md) and [Add Records](/codemash/cloud/database/collections/add-records.md) use these routes.

## Use it from code

TS `norbix.hub.database.findRecords / insertRecord / updateOneRecord / …` · Python `hub.database.find_records / insert_record / …` · Go `c.Hub.Database.FindRecords / …` · .NET `FindRecordsAsync(new FindRecords { … })`. The data-plane methods are `norbix.api.database.find / insertOne / …`.
