Data Access

Writing Data

Create, update, and delete items in your collections.

The fields parameter on write operations controls which fields are included in the response — it does not affect which data is written. All fields in data are always persisted.

Use include alongside fields to return related data, using the same syntax as read requests. See Field Selection for syntax details.

Create a Single Item

Creates a single item in the collection and returns it. Send a POST request with the item data in the request body.

const newArticle = await client.Articles.createOne({
  data: { title: 'Getting Started with Monospace', status: 'draft' },
  fields: ['id', 'title', 'status'],
});

Create Multiple Items at Once

Creates several items in a single request. The request body is always an array of objects.

const newTags = await client.Tags.createMany({
  data: [{ name: 'TypeScript' }, { name: 'GraphQL' }, { name: 'REST' }],
  fields: ['id', 'name'],
});

Update a Single Item by ID

Patches a single item identified by its primary key. Only the provided fields are modified — all other fields remain unchanged. Send a PATCH request with the fields you want to change.

const updated = await client.Articles.updateOne({
  key: 1,
  data: { status: 'published', published_at: '2026-02-25T12:00:00Z' },
  fields: ['id', 'status', 'published_at'],
});

Update Multiple Items by Filter

Updates all items matching a filter. The same changes are applied to every matched item.

const archived = await client.Articles.updateMany({
  filter: { status: { _eq: 'draft' }, created_at: { _lt: '2025-01-01' } },
  data: { status: 'archived' },
  fields: ['id', 'status'],
});

Delete a Single Item by ID

Permanently removes a single item identified by its primary key. The response is a { data } envelope. Add fields to return the deleted item in data.

await client.Comments.deleteOne({ key: 99 });

Delete Multiple Items by Filter

Permanently removes all items matching a filter in a single request.

await client.Comments.deleteMany({
  filter: { flagged: { _eq: true } },
});
Warning
Bulk deletes are irreversible. Double-check your filter before executing.

Return the Result After Writing

Add the fields parameter to any create or update request to return the written data in the response. This saves a follow-up read request. To return related data, add include alongside fields, using the same syntax as read requests.

const article = await client.Articles.createOne({
  data: { title: 'Return Fields on Write', status: 'draft' },
  fields: ['id', 'title', 'status', 'created_at'],
});
Tip
Create related items inline — see Relational Data.

See Also

  • Filtering — build filters for bulk updates and deletes
  • Relational Data — nested relational operations (connect, create, disconnect, update, delete)
  • Errors — handle validation errors and conflicts

MonospaceThe governed API layer for every app, person, and agent.

Copyright © 2026 Monospace Inc.