Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Prisma · Module

deleteMany

deleteMany removes multiple records matching an optional filter. Prisma executes it transactionally and reports how many records were deleted.

How it works

Call a model's deleteMany method with an optional where filter. Prisma runs the bulk deletion transactionally and returns a count of deleted records; an empty filter targets every record of that model.

Syntax

prisma.<model>.deleteMany({ where?: <Model>WhereInput })

Parameters

NameTypeDescription
whereUserWhereInput (model-specific WhereInput)Optional filter containing model fields and conditions that determine which records are deleted.

Returns

BatchPayload containing the number of deleted records.

Key points

  • Use the model delegate's deleteMany method when one operation should remove multiple matching records.
  • Provide a where filter to select records by model fields and conditions.
  • In supported nested relation operations, nested deleteMany can remove related records matching a filter.

Common mistakes

  • When combining dependent bulk deletions in $transaction, arrange them in an order that satisfies the relation constraints; dependent records may need deletion first.

Example: Delete matching users

import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

async function main() {
  const result = await prisma.user.deleteMany({
    where: { email: { contains: "prisma.io" } },
  });
  console.log(`Deleted ${result.count} users`);
}

main().finally(() => prisma.$disconnect());

Deletes every User whose email contains prisma.io and reports the number removed.

When to use it

Filtered bulk cleanup

Remove records matching conditions such as an email substring, status, date range, or other model fields.

Test database cleanup

Clear a model during test teardown when the schema and relation order are known.

Transactional relational cleanup

Delete dependent records across several models in a coordinated operation.

Interview questions

QWhat does Prisma deleteMany do, and what does it return?

deleteMany removes all records matching the optional where filter and returns a BatchPayload containing the deleted count. The operation runs in a transaction.

Follow-up: How would you delete related records safely? Use separate deleteMany calls in dependency order, or combine them in $transaction so the operations are coordinated atomically.

QHow do you delete only selected records?

An empty filter can delete every record for the selected model. A where condition narrows the operation to matching records, such as users whose email contains a particular string.

Follow-up: What risk does an omitted filter create? It can remove the entire model's dataset, so construct and validate the filter deliberately before executing it.

QHow should several bulk deletions be coordinated?

Multiple deleteMany operations can be placed in $transaction([]). Prisma executes the batch as a transaction, and dependent deletions should be ordered so child records are removed before parent records.

Follow-up: What happens if one operation fails? The transaction rolls back the entire operation, preserving atomicity.

  • delete
  • updateMany
  • createMany
  • $transaction
  • UserWhereInput

Source: Prisma Client API (Prisma ORM v7). Checked 2026-10-16.