Update a single record
Change fields on one known record selected by a unique identifier or constraint.
Prisma · Module
Prisma Client’s update() changes one existing record selected by where and returns it. Use updateMany() for bulk changes, or updateManyAndReturn() when the updated objects are needed on supported databases.
Prisma Client's update() method selects one existing record with a unique where condition, applies the changes in data, and returns the updated record. Use updateMany() when the operation should affect a batch and return only the number of changed records.
prisma.<model>.update({ where: <unique selector>, data: <update input> })| Name | Type | Description |
|---|---|---|
where | WhereUniqueInput | Unique selector identifying the record to update. |
data | UpdateInput | Field assignments and nested relation operations to apply. |
update() returns the updated record; updateMany() returns the number of updated records. updateManyAndReturn() returns the updated records on supported databases.
updateMany() for bulk changes; its result reports how many records were updated.upsert instead of update.const updatedUser = await prisma.user.update({
where: { email: "viola@prisma.io" },
data: { name: "Viola the Magnificent" },
});
console.log(updatedUser);Updates the matching user and returns the resulting record.
Change fields on one known record selected by a unique identifier or constraint.
Apply the same field changes to every record matching a filter.
Modify related records while updating their parent record.
Guard writes against concurrent changes with a version-based filter.
update() and updateMany() differ?update() modifies one record selected by where and returns that record. updateMany() applies changes to all matching records and returns the number updated.
Follow-up: When should updateManyAndReturn() be used? Use it when multiple updated objects are needed; the documentation lists PostgreSQL, CockroachDB, and SQLite as supported databases.
A nested update changes related records as part of a top-level update. It is only valid within a parent update query.
Follow-up: What happens if the related record is absent? Prisma Client throws an exception rather than silently creating it.
For optimistic concurrency control, include a version field in the filter so the update checks whether the record changed during execution. The documentation also notes that non-unique fields can be used to enforce permissions during an update.
Follow-up: What limitation applies to older Prisma versions? Versions 4.4.0 and earlier cannot filter update operations on non-unique fields.
updateManyupdateManyAndReturnupsertnested updateoptimistic concurrency controlversion field