Bulk create duplicate error

AppId:

In the ResultFullList I have the full data set of League table with updated column, I want to save the list to League table as a way to update these columns. I use these blocks to bulk create, but it always says “Error: Duplicate entry ‘xxxxxxx’ for key ‘PRIMARY’ at new ResponseError”. Why is this happening? Ps: When I use loop to save object one by one it works, but I want to do this with bulk with 100 objects at once. There are more than 100 objects in the list that’s why I use these blocks.

image

Hi Louis,

When you save objects individually, there is a check whether the object has a value for the objectId property. If it does, the server updates the object in the database, otherwise a new one is created. The “Bulk create” operation doesn’t perform that check, it expects that all objects are new. Therefore when an object has a value for the objectId property, the error is returned.

Regards,
Mark

1 Like

Thanks @mark-piller

I created this function to update the ranking of players in my database, but when there are many players, saving individually will greatly increase the amount of API calls. Every time there is a new game result, it means hundreds of API calls due to saving one by one. Is there any other way to solve this?

Hi @Louis,

this would be possible if the changes were the same for all objects. E.g. you would need to update all objects by some criteria with the value Score: 100. But in this particular case, you need to update the individual values for each of the objects. And unfortunately, so far I don’t see any other way to update them all at once.

Regards,
Stanislaw

Thanks anyway @stanislaw.grin @mark-piller

If there comes some new functions to support this scenario in bulk please let us know!