> 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.md).

# Collections

Database → Collections endpoints.

**Collections** hold your records. Norbix generates a full CRUD + query API over each collection from its schema, with record-level ownership and triggers.

| Endpoint                                                                                                     | Method                                                               |
| ------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------- |
| [Aggregate](/codemash/api-reference/database/collections/aggregate.md)                                       | `POST collections/{collectionName}/aggregate`                        |
| [Change Responsibility](/codemash/api-reference/database/collections/change-responsibility.md)               | `PUT collections/{collectionName}/{id}/responsibility`               |
| [Count](/codemash/api-reference/database/collections/count.md)                                               | `GET collections/{collectionName}/count`                             |
| [Delete Many](/codemash/api-reference/database/collections/delete-many.md)                                   | `DELETE collections/{collectionName}/many`                           |
| [Delete One](/codemash/api-reference/database/collections/delete-one.md)                                     | `DELETE collections/{collectionName}/{id}`                           |
| [Distinct](/codemash/api-reference/database/collections/distinct.md)                                         | `GET collections/{collectionName}/distinct`                          |
| [Execute Aggregate](/codemash/api-reference/database/collections/execute-aggregate.md)                       | `POST collections/{collectionName}/aggregates/{aggregateId}/execute` |
| [Find](/codemash/api-reference/database/collections/find.md)                                                 | `GET collections/{collectionName}`                                   |
| [Find One](/codemash/api-reference/database/collections/find-one.md)                                         | `GET collections/{collectionName}/{id}`                              |
| [Find Own](/codemash/api-reference/database/collections/find-own.md)                                         | `GET collections/{collectionName}/own`                               |
| [Insert Many](/codemash/api-reference/database/collections/insert-many.md)                                   | `POST collections/{collectionName}/many`                             |
| [Insert One](/codemash/api-reference/database/collections/insert-one.md)                                     | `POST collections/{collectionName}`                                  |
| [Replace One](/codemash/api-reference/database/collections/replace-one.md)                                   | `PUT collections/{collectionName}/{id}/replace`                      |
| [Update Many](/codemash/api-reference/database/collections/update-many.md)                                   | `PUT collections/{collectionName}/many`                              |
| [Update One](/codemash/api-reference/database/collections/update-one.md)                                     | `PUT collections/{collectionName}/{id}`                              |
| [Aggregate Records](/codemash/api-reference/database/collections/aggregate-records.md)                       | `POST collections/{collectionName}/aggregate`                        |
| [Change Record Responsibility](/codemash/api-reference/database/collections/change-record-responsibility.md) | `PUT collections/{collectionName}/{id}/responsibility`               |
| [Count Records](/codemash/api-reference/database/collections/count-records.md)                               | `GET collections/{collectionName}/count`                             |
| [Delete Many Records](/codemash/api-reference/database/collections/delete-many-records.md)                   | `DELETE collections/{collectionName}/many`                           |
| [Delete Record](/codemash/api-reference/database/collections/delete-record.md)                               | `DELETE collections/{collectionName}/{id}`                           |
| [Distinct Record Values](/codemash/api-reference/database/collections/distinct-record-values.md)             | `GET collections/{collectionName}/distinct`                          |
| [Execute Records Aggregate](/codemash/api-reference/database/collections/execute-records-aggregate.md)       | `POST collections/{collectionName}/aggregates/{aggregateId}/execute` |
| [Find One Record](/codemash/api-reference/database/collections/find-one-record.md)                           | `GET collections/{collectionName}/{id}`                              |
| [Find Records](/codemash/api-reference/database/collections/find-records.md)                                 | `GET collections/{collectionName}`                                   |
| [Get Collection Indexes](/codemash/api-reference/database/collections/get-collection-indexes.md)             | `GET collections/{collectionName}/indexes`                           |
| [Insert Many Records](/codemash/api-reference/database/collections/insert-many-records.md)                   | `POST collections/{collectionName}/many`                             |
| [Insert Record](/codemash/api-reference/database/collections/insert-record.md)                               | `POST collections/{collectionName}`                                  |
| [Replace Record](/codemash/api-reference/database/collections/replace-record.md)                             | `PUT collections/{collectionName}/{id}/replace`                      |
| [Seed Collection Records](/codemash/api-reference/database/collections/seed-collection-records.md)           | `POST collections/seed`                                              |
| [Update Many Records](/codemash/api-reference/database/collections/update-many-records.md)                   | `PUT collections/{collectionName}/many`                              |
| [Update One Record](/codemash/api-reference/database/collections/update-one-record.md)                       | `PUT collections/{collectionName}/{id}`                              |

**Hub only** (developer / admin plane):

| Endpoint                                                                                           | Method                                      |
| -------------------------------------------------------------------------------------------------- | ------------------------------------------- |
| [Hub record endpoints](/codemash/api-reference/database/collections/hub-records.md)                | the same record routes as above, on the Hub |
| [Seed Collection Records](/codemash/api-reference/database/collections/seed-collection-records.md) | `POST collections/seed`                     |
| [Get Collection Indexes](/codemash/api-reference/database/collections/get-collection-indexes.md)   | `GET collections/{collectionName}/indexes`  |

## Rules for every record endpoint

* `filter`, `document`, `update` and `pipeline` are JSON **strings**.
* Inserts **and** updates (`Update One`, `Update Many`) are validated against the collection's published schema.
* A filter or pipeline with `$where`, `$function` or `$accumulator`, or a read pipeline with `$out` / `$merge`, is refused with `CM-ERRORS-DATABASE-031`.
* Without `databaseIntegrationId` the default database 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.

In Cloud: [Records](/codemash/cloud/database/collections/records.md).
