Update different records in table with different values
See original GitHub issueProblem
Lets consider a user table with columns ID
and NAME
. If i wish to update multiple Names
based on their IDs
, for example -
- For id=1, name should be updated to name=“abc”
- For id=2, name should be updated to name=“def”
- For id=3, name should be updated to name=“xyz”
I can’t do that in one single query.
Suggested solution
There should be a way to bulk update records in a table with different values. For example -
prisma.user.updateMany({ where:{ id: { in: [1,2,3] } }, data:{ name:["abc", "def", "xyz"] } })
OR
prisma.user.updateMany({ [ { where:{ id: 1 }, data:{ name:"abc" } }, { where:{ id: 2 }, data:{ name:"def" } }, ] })
Alternatives
It can’t be done using updateMany since it only allows to update all records with one single piece of data.
For example -
prisma.user.updateMany({ where:{ id: { in: [1,2,3] } }, data:{ name: "abc" } })
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Reactions:36
- Comments:7
Top GitHub Comments
Would be very inresting – instead of currently using the combo
map
&update
It doesn’t make any sense when you have to update thousands of documents to thousands of different values to perform thousands of updates, if you know from the beginning the information you want to update, so not being able to do this type of operation limits a lot for performance reasons.
We will need to be able to use something like bulkWrite (https://www.mongodb.com/docs/manual/reference/method/db.collection.bulkWrite/)