Sequelize: insert in bulk
Below is the correct syntax for bulk update, Tested on "sequelize": "6.0.0"
model.bulkCreate(dataToUpdate, { updateOnDuplicate: ["user_id", "token", "created_at"] })
It will update all the columns specfied in updateOnDuplicate by first column values which are in dataToUpdate
Pass in an options object to bulkCreate with ignoreDuplicates set to true
bulkCreate([...], { ignoreDuplicates: true })
ProductAttribute.bulkCreate(arrayToUpsert, {updateOnDuplicate: ['id', 'attributeValue'] })
- this will update each attributeValue with ids indicated in arrayToUpsert
Yuri's answer will ignore duplicates... there is an option for updateOnDuplicate
:
Fields to update if row key already exists (on duplicate key update)? (only supported by mysql & mariadb). By default, all fields are updated.
http://docs.sequelizejs.com/en/latest/api/model/#bulkcreaterecords-options-promisearrayinstance