// AND const result = await prisma.modelName.findMany({ where: { AND: [ { field1: 'value1' }, { field2: 'value2' } ] } }); // OR const result = await prisma.modelName.findMany({ where: { OR: [ { field1: 'value1' }, { field2: 'value2' } ] } });
When operator is not defined, it defaults to an AND
:
const result = await prisma.modelName.findMany({ where: { { field1: "value1" }, { field2: "value2" } } });
findUnique()
Retrieve a single database record.
Replaced findOne
in version 2.12.0
.
Cannot take multiple where clause conditions, use
findFirst
instead
const result = await prisma.user.findUnique({ where: { id: 42, }, });
findFirst()
Returns the first record in a list that matches the criteria.
const result = prisma.user.findFirst({ where: { AND: [ { id: { mode: 'insensitive', equals: id, }, }, { age: { equals: age, }, }, ], }, });
findMany
findMany
defaults to AND
Below where
clause will return records that match both name
and email
field conditions
where: { name: { in: ['Sam', 'Clemens', 'Bob'], }, email: { contains: 'example.com', }, }
Override the default AND
behavior by using OR[]
field wrapping
where: { OR: [ { name: { in: ['Sam', 'Clemens', 'Bob'], }, }, { email: { contains: 'example.com' }, }, ], }
in
Find values that exist in the list
null
values are not returned
in
and NOT
to return user
whose name
is not in the list, users with null
value names are not returnedExample: Get User
records where the id
can be found in the following list:
[22, 91, 14, 2, 5]
const getUser = await prisma.user.findMany({ where: { id: { in: [22, 91, 14, 2, 5] }, }, });
NOT
Exclude records from the result set using the NOT
field
const getUser = await prisma.user.findMany({ where: { NOT: { name: { in: ['Saqui', 'Clementine', 'Bob'] }, }, }, })