> 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/cloud/database/collections/add-records.md).

# Add or edit a record

Add a record to a collection, or change one, with the form built from the collection's schema.

**Where:** Database → Collections → *collection* → **Add New** (or **Edit** on a row) · `/projects/<project>/db/collections/<collection>/records/new` · `…/records/<recordId>/edit`

## Before you start

* The collection's schema is **published** — see [Create a schema](/codemash/cloud/database/collections/create-schema.md). **Add New** is off while the schema is only a draft.
* You need `database:create` on the collection (`database:collection:<name>`) to add, `database:update` to edit.

## Steps

1. Open **Database → Collections**, click the collection, and press **Add New**. The form is titled **Add New Record — books (v1)**: the collection and its published version. Its fields, widgets and tabs come from the schema.

   <figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-abd75d6d5d094745c85e054b472295e2d39fc13d%2Fadd-records-1.png?alt=media" alt="Add New Record — books (v1): Create a new record in the books collection. One tab Book with the empty fields Title, Pages, an In stock checkbox and a Genre select; Cancel and Create"><figcaption><p>The empty record form of books.</p></figcaption></figure>
2. Fill in the fields. Switch tabs, if the schema has several, to reach every field.

   | Field    | Required | What it does                                           | Example            |
   | -------- | -------- | ------------------------------------------------------ | ------------------ |
   | Title    | yes      | Text, at most 200 characters.                          | `The Dispossessed` |
   | Pages    | yes      | A whole number, 0 or more.                             | `387`              |
   | In stock | no       | Yes / no.                                              | ticked             |
   | Genre    | no       | One value of the list `fiction`, `science`, `history`. | `fiction`          |

   <figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-0eb9c69ee07ebe25fd9d69fb575741b0666920ad%2Fadd-records-2.png?alt=media" alt="The record form filled in: Title The Dispossessed, Pages 387, In stock ticked, Genre fiction"><figcaption><p>The form, filled in.</p></figcaption></figure>
3. Press **Create**. Required fields and formats are checked first; an invalid form is not sent. **Cancel** goes back without saving.

## Result

Cloud goes back to the records list, and the new record is the first row (newest first, unless the [List tab](/codemash/cloud/database/collections/schema-indexes.md) sets another sort). The record gets an id (`6ac4f314f002ebc3670fbf05`), and every [schema trigger](/codemash/cloud/database/collections/schema-triggers.md) **When inserted** runs.

<figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-6aa4e8e7a9252b7c060a024aba7e1af7babc7dbb%2Fadd-records-3.png?alt=media" alt="Records list of books with the new row The Dispossessed, 387, True, fiction at the top"><figcaption><p>The new record in the list.</p></figcaption></figure>

## Change or remove it later

* **Edit** — press **Edit** on the row. The form is titled **Edit Record — books (v1)**, shows the saved values, and its button is **Update**. Change the values and press **Update**; **When updated** triggers run.

  <figure><img src="https://712692422-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHy372bqsaex2cqS3ikhL%2Fuploads%2Fgit-blob-11fb5d41b53fa727694b8ed7908c65239d1b4e8b%2Fadd-records-4.png?alt=media" alt="Edit Record — books (v1) for Neuromancer, 271 pages, In stock ticked, Genre fiction; a red Delete button at the top right; Cancel and Update"><figcaption><p>Editing a record.</p></figcaption></figure>
* **Delete** — **Delete** at the top right of the edit form, or **Delete...** on the row — see [Delete a record](/codemash/cloud/database/collections/delete-record.md).
* The record's owner (schema setting **Records have an owner**) is not changed here; use `changeResponsibility` from code.

The API checks inserts **and** updates against the published schema: a value the schema forbids is refused, from Cloud and from code.

## Do it from code

```ts
const { id } = await norbix.api.database.insertOne({
  collectionName: 'books',
  document: JSON.stringify({ title: 'The Dispossessed', pages: 387, in_stock: true, genre: 'fiction' }),
});
await norbix.api.database.updateOne({
  collectionName: 'books',
  id,
  update: JSON.stringify({ pages: 400 }),
});
```

```sh
norbix api database one insert --collectionName books --document '{"title":"Solaris","pages":204,"in_stock":true,"genre":"fiction"}'
```

`updateOne` takes the fields to change, not `$` operators (`CM-ERRORS-DATABASE-035`). The client setup is on the [Database page](/codemash/cloud/database.md#use-it-from-code). API: [Insert One](/codemash/api-reference/database/collections/insert-one.md) · [Update One](/codemash/api-reference/database/collections/update-one.md) · [Replace One](/codemash/api-reference/database/collections/replace-one.md) · [Change Responsibility](/codemash/api-reference/database/collections/change-responsibility.md)
