Bulk field updates
Change a field across a filtered group of existing records, such as assigning a role to users matching an email condition.
Prisma · Module
updateMany applies one set of field changes to every record matching a filter. It returns the number of records updated.
Call a model delegate's updateMany method with a where filter and a data object. Prisma applies the data changes to every record matching the filter and returns an object containing the number of updated records; bulk operations run transactionally.
prisma.<model>.updateMany({ where, data })| Name | Type | Description |
|---|---|---|
where | ModelWhereInput | Conditions selecting the records to update; the page documents this as the where argument. |
data | XOR<ModelUpdateManyMutationInput, ModelUncheckedUpdateManyInput> | Fields and values to apply to every selected record; the page documents this as the data argument. |
A result object containing count, the number of records updated.
data object supplies the new field values applied to each matching record.updateMany; use a supported nested write context or separate operations instead.const result = await prisma.user.updateMany({
where: {
email: { contains: "prisma.io" },
},
data: {
role: "ADMIN",
},
});
console.log(result.count);Updates every matching user and prints the number of records changed.
Change a field across a filtered group of existing records, such as assigning a role to users matching an email condition.
Apply a status transition to all records meeting a business predicate, such as marking matching items processed.
Perform several independent writes with transactional behavior by combining bulk updates through Prisma's transaction API.
updateMany do and what does it return?updateMany performs a bulk update against all records selected by where, using the changes specified in data. Its result reports how many records were updated rather than returning the updated rows.
Follow-up: How can several independent updates be made atomic? Use Prisma's transaction API, such as $transaction([]), to execute them as one atomic operation.
where and data work together?The where argument limits the records, while data describes the fields to change. For example, a filter can match users whose email contains a domain and assign those users an administrative role.
Follow-up: What should be considered when the filter is broad? Verify the predicate carefully because every matching record is changed in the bulk operation.
Bulk operations, including updateMany, run as transactions. If a batch operation fails, the transaction behavior prevents a partial successful result within that operation.
Follow-up: How does this differ from nested writes? updateMany itself does not support nested writes, so related-record changes need a supported operation or separate transactional calls.
updateupdateManyAndReturndeleteMany$transaction([])