N
N
NewSantaClaus2021-10-07 10:15:58
Node.js
NewSantaClaus, 2021-10-07 10:15:58

How to write a string to the database in sequalize (nodejs) if it is not there?

I have an array of objects
Example.

const arr = [
  {...},
  {...},
  {...}
]


Each object has a field, for example a, which is designated as a unique column in the database.

Question. How can I write the data from that array to the database so as not to check each field for presence.

Now I am writing like this. But the downside is that if at least one object from the array is already in the database, an error occurs and the rest are not recorded

Transaction.bulkCreate(arr)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fedor Vlasenko, 2021-10-07
@NewSantaClaus

https://sequelize.org/master/class/lib/model.js~Mo...
3rd parameter
ignoreDuplicates, updateOnDuplicate

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question