# Working with scalar lists (Prisma ORM v6) (/docs/orm/v6/prisma-client/special-fields-and-types/working-with-scalar-lists-arrays)

How to read, write, and filter by scalar lists / arrays.

Location: ORM > v6 > Prisma Client > Special Fields and Types > Working with scalar lists

[Scalar lists](/guides/reference-6-v6-reference-prisma-schema-reference#-modifier) are represented by the `[]` modifier and are only available if the underlying database supports scalar lists. The following example has one scalar `String` list named `pets`:

#### Relational databases

```prisma highlight=4;normal 
model User {
  id   Int      @id @default(autoincrement())
  name String
  pets String[] // [!code highlight]
}
```

#### MongoDB

```prisma highlight=4;normal 
model User {
  id   String   @id @default(auto()) @map("_id") @db.ObjectId
  name String
  pets String[] // [!code highlight]
}
```

Example field value:

```json5
["Fido", "Snoopy", "Brian"]
```

## Setting the value of a scalar list

The following example demonstrates how to [`set`](/guides/reference-6-v6-reference-prisma-client-reference#set-1) the value of a scalar list (`coinflips`) when you create a model:

```ts
const createdUser = await prisma.user.create({
  data: {
    email: "eloise@prisma.io",
    coinflips: [true, true, true, false, true],
  },
});
```

## Unsetting the value of a scalar list

> \[!WARNING]
> This method is available on MongoDB only in versions
> [3.11.1](https://github.com/prisma/orm/releases/tag/3.11.1) and later.

The following example demonstrates how to [`unset`](/guides/reference-6-v6-reference-prisma-client-reference#unset) the value of a scalar list (`coinflips`):

```ts
const createdUser = await prisma.user.create({
  data: {
    email: "eloise@prisma.io",
    coinflips: {
      unset: true,
    },
  },
});
```

Unlike `set: null`, `unset` removes the list entirely.

## Adding items to a scalar list

> \[!WARNING]
> Available for:
>
> - PostgreSQL in versions [2.15.0](https://github.com/prisma/orm/releases/tag/2.15.0) and later
> - CockroachDB in versions [3.9.0](https://github.com/prisma/orm/releases/tag/3.9.0) and later
> - MongoDB in versions [3.11.0](https://github.com/prisma/orm/releases/tag/3.11.0) and later

Use the [`push`](/guides/reference-6-v6-reference-prisma-client-reference#push) method to add a single value to a scalar list:

```ts
const userUpdate = await prisma.user.update({
  where: {
    id: 9,
  },
  data: {
    coinflips: {
      push: true,
    },
  },
});
```

In earlier versions, you have to overwrite the entire value. The following example retrieves user, uses `push()` to add three new coin flips, and overwrites the `coinflips` field in an `update`:

```ts
const user = await prisma.user.findUnique({
  where: {
    email: "eloise@prisma.io",
  },
});

if (user) {
  console.log(user.coinflips);

  user.coinflips.push(true, true, false);

  const updatedUser = await prisma.user.update({
    where: {
      email: "eloise@prisma.io",
    },
    data: {
      coinflips: user.coinflips,
    },
  });

  console.log(updatedUser.coinflips);
}
```

## Filtering scalar lists

> \[!WARNING]
> Available for:
>
> - PostgreSQL in versions [2.15.0](https://github.com/prisma/orm/releases/tag/2.15.0) and later
> - CockroachDB in versions [3.9.0](https://github.com/prisma/orm/releases/tag/3.9.0) and later
> - MongoDB in versions [3.11.0](https://github.com/prisma/orm/releases/tag/3.11.0) and later

Use [scalar list filters](/guides/reference-6-v6-reference-prisma-client-reference#scalar-list-filters) to filter for records with scalar lists that match a specific condition. The following example returns all posts where the tags list includes `databases` _and_ `typescript`:

```ts
const posts = await prisma.post.findMany({
  where: {
    tags: {
      hasEvery: ["databases", "typescript"],
    },
  },
});
```

### `NULL` values in arrays

> \[!WARNING]
> This section applies to:
>
> - PostgreSQL in versions [2.15.0](https://github.com/prisma/orm/releases/tag/2.15.0) and later
> - CockroachDB in versions [3.9.0](https://github.com/prisma/orm/releases/tag/3.9.0) and later

When using scalar list filters with a relational database connector, array fields with a `NULL` value are not considered by the following conditions:

- `NOT` (array does not contain X)
- `isEmpty` (array is empty)

This means that records you might expect to see are not returned. Consider the following examples:

- The following query returns all posts where the `tags` **do not** include `databases`:

  ```ts
  const posts = await prisma.post.findMany({
    where: {
      NOT: {
        tags: {
          has: "databases",
        },
      },
    },
  });
  ```

  - ✔ Arrays that do not contain `"databases"`, such as `{"typescript", "graphql"}`
  - ✔ Empty arrays, such as `[]`

  The query does not return:

  - ✘ `NULL` arrays, even though they do not contain `"databases"`

The following query returns all posts where `tags` is empty:

```ts
const posts = await prisma.post.findMany({
  where: {
    tags: {
      isEmpty: true,
    },
  },
});
```

The query returns:

- ✔ Empty arrays, such as `[]`

The query does not return:

- ✘ `NULL` arrays, even though they could be considered empty

To work around this issue, you can set the default value of array fields to `[]`.

## Related pages

- [`Composite types`](/guides/prisma-client-v6-special-fields-and-types-composite-types): Learn about composite types in Prisma Client for MongoDB
- [`Null and undefined`](/guides/prisma-client-v6-special-fields-and-types-null-and-undefined): How Prisma Client handles null and undefined
- [`Working with compound IDs and unique constraints`](/guides/prisma-client-v6-special-fields-and-types-working-with-composite-ids-and-constraints): How to read, write, and filter by compound IDs and unique constraints.
- [`Working with Json fields`](/guides/prisma-client-v6-special-fields-and-types-working-with-json-fields): How to read, write, and filter by Json fields.

## Related pages

- [Authentication & Tools](./authentication-tools-index.md)
- [Build](./build-index.md)
- [Changelog](../changelog.md)
- [Concepts](./concepts-index.md)
- [Console commands](./console-commands-index.md)
- [Contract Authoring](./contract-authoring-index.md)
- [Core Concepts](./core-concepts-index.md)
- [Data Modeling](./data-modeling-index.md)
- [Database](./database-index.md)
- [DB commands](./db-commands-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
