1

object array like [{id: 1, a: 1, b: 2}, {id: 2, a: 3, b:4}]. and I hope to upsert the array to database using sequelize upsert at once. can it support array or should use loop to do it?

dyh333
  • 385
  • 1
  • 5
  • 15

1 Answers1

1

you can use updateOnDuplicate along with bulkCreate method as follows

model.bulkCreate(dataArray, { 
  updateOnDuplicate: [ 'a', 'b' ] // array of fields to update 
}).then(()=> {});

this is only supported by mysql

reference bulkCreate

Aditya Kokil
  • 423
  • 4
  • 11