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?
-
I see that the array contain id. It's mean that you only want update value. Right?– Chuong TranMar 5, 2019 at 3:12
Add a comment
|
1 Answer
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
-
In document option updateOnDuplicate is Array. Pls update your answer Mar 5, 2019 at 3:32
-
-
1Link to reference is wrong, bulkCreate: sequelize.org/api/v6/class/src/…– PuceApr 26, 2022 at 13:36