bulkUpdate in sequelize orm

前端 未结 2 373
天涯浪人
天涯浪人 2021-01-04 07:38

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

2条回答
  •  失恋的感觉
    2021-01-04 08:03

    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

提交回复
热议问题