Update and consume changed records
A batch change must immediately be sent to another service or displayed to a caller.
Prisma · Module
updateManyAndReturn() updates multiple matching records and returns the resulting objects. Prisma documents it for PostgreSQL, CockroachDB, and SQLite in Prisma ORM 6.2.0 and later.
Call the generated model method with a filter in where and the changes in data. It updates every matching record and returns the resulting objects, making the changed rows available immediately instead of only reporting how many rows were affected.
prisma.<model>.updateManyAndReturn({ where?, data, select?, omit? })| Name | Type | Description |
|---|---|---|
where | UserWhereInput | Filter identifying the records to update. |
data | UserUpdateManyMutationInput | Values and supported update operations applied to each matching record. |
An array of the updated model records.
prisma.user, to invoke it.join relation load strategy cannot be used with this operation.const users = await prisma.user.updateManyAndReturn({
where: { email: { contains: "prisma.io" } },
data: { role: "ADMIN" },
});Updates matching users and returns their updated records.
A batch change must immediately be sent to another service or displayed to a caller.
A migration or administration task changes a filtered group of rows.
An application applies the same field change to all records matching a condition.
updateManyAndReturn() do, and how does it differ from updateMany()?It updates multiple records selected by where and returns the resulting objects. Unlike updateMany(), which returns only the number of updated records, this method returns the updated rows.
Follow-up: Which databases support it? Prisma documents support for PostgreSQL, CockroachDB, and SQLite.
The method is available starting with Prisma ORM 6.2.0. Its returned value is a list of the updated model objects, subject to the operation's selection options.
Follow-up: What should be checked before adopting it in a project? Confirm the Prisma ORM version and database provider meet the documented support requirements.
Use where to identify the records and data to specify the update applied to each match. For example, an email filter can select users while data changes their role.
Follow-up: How can relation loading affect the call? The documented join relation load strategy is unavailable for this method.
updateMany()createManyAndReturn()deleteMany()wheredatarelationLoadStrategy