---
title: update
description: Update existing records in your database
icon: pencil
---

`update` modifies a single record matched by a unique identifier and returns it. It throws if the record doesn't exist.

```ts
const user = await client.user.update({
  where: { id: "user_123" },
  data: { name: "Alice Smith" },
});
```

## Conditional Updates

The `where` may narrow the unique lookup with ordinary non-unique scalar filters
and `AND` / `OR` / `NOT` — a compare-and-set, in one statement:

```ts
// bump the version only if it is still the one we read
await client.document.update({
  where: { id: "doc_1", version: 7 },
  data: { body, version: { increment: 1 } },
});
```

If the unique key matches but the filter excludes the row, the update is a
`NotFoundError` and **nothing is written** — not a silent no-op. See
[Narrowing a Unique Lookup](/docs/client/find-unique#narrowing-a-unique-lookup)
for the full `where` shape and its two divergences from Prisma.

## Scalar Operations

```ts
// Set value
await client.post.update({
  where: { id: "post_123" },
  data: { title: "New Title" },
});

// Increment/decrement numbers
await client.post.update({
  where: { id: "post_123" },
  data: {
    views: { increment: 1 },
    likes: { decrement: 1 },
  },
});

// Multiply/divide
await client.product.update({
  where: { id: "product_123" },
  data: {
    price: { multiply: 1.1 },  // 10% increase
  },
});

// Array operations
await client.post.update({
  where: { id: "post_123" },
  data: {
    tags: { push: "new-tag" },
  },
});
```

## With Relations

Depending on relation cardinality and whether its membership can be cleared,
an `update` can use `create`, `connect`, `connectOrCreate`, `disconnect`,
`delete`, `set`, `update`, `updateMany`, `upsert`, and `deleteMany`:

```ts
await client.user.update({
  where: { id: "user_123" },
  data: {
    posts: {
      create: { title: "New Post" },
    },
  },
});
```

See [Nested writes](/docs/client/nested-writes) for each operation.

## Options

```ts
await client.user.update({
  where: { ... },       // Required: unique identifier
  data: { ... },        // Required: fields to update
  select: { ... },      // Optional: fields to return
  include: { ... },     // Optional: relations to include
});
```

`select` and `include` control the returned shape — see [Selecting Fields](/docs/client/selecting).

## Examples

### Update Profile

This uses to-one nested `update`; it throws if no correlated profile exists.

```ts
async function updateProfile(userId: string, data: { name?: string; bio?: string }) {
  return client.user.update({
    where: { id: userId },
    data: {
      name: data.name,
      profile: {
        update: { bio: data.bio },
      },
    },
    include: { profile: true },
  });
}
```

### Increment View Count

```ts
async function recordView(postId: string) {
  return client.post.update({
    where: { id: postId },
    data: {
      views: { increment: 1 },
      lastViewedAt: new Date(),
    },
  });
}
```
