#23016·Prisma

Filter by the size of a scalar list

Author: boredlandCreated Feb 8, 2024Updated Sep 13, 2026
Labelskind/featuretech/enginestech/typescripttopic: where / filtertopic: client apitopic: scalar list

Problem

When defining a scalar list like so:

  matchIds  String[] @db.ObjectId

We should be able to find entities with at least, at most or exact a count of elements in the list.

In mongodb, that is easily possible, in pg afaik too via JSONB_ARRAY_LENGTH. For prisma I seem to be only able to filter on emptyness via isEmpty, so a count of 0.

Suggested solution

Provide a _count to the where clause of a scalar list.

Alternatives

Filtering post query in ram or via a raw query.