bulkUpdate in sequelize orm

别来无恙 提交于 2020-06-10 21:18:04

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/54898994/bulkupdate-in-sequelize-orm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!