Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

How can we implement bulkUpdate like bulkCreate in sequelize orm, I searched the whole documentation of sequelize but didn't find anything related to bulkUpdate, so I tried to loop update in for loop, it works but is there any other way to update in bulk

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
742 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use the bulkCreate to bulkUpdate method.

bulkCreate([...], { updateOnDuplicate: ["name"] })

updateOnDuplicate is an array of fields that will be updated when the primary key (or may be unique key) match the row. Make sure you have at least one unique field (let say id) in your model and in the dataArray both for upsert.

For reference refer here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...