have social media pp in which I have account id and account type on frontend side. On server side when I receive these account details i.e array of object each having account info. So I store access_token corresponding to each account and this logic is handled on server side. So if I am looping on each account what if one fails to store access token in db and others don't. Should I use upsert in this case if failed then upsert otherwise insert or should I use db transactions i.e add access token for all accounts or none
You need transactions when you have to do multiple sql operations that should be performed all, or in case of error none
In my case I am using mongodb to update multiple documents inside collection so for that should I use transactions or no? Because on each document I am making API request to third party service.
Transactions on mongo? 😀 wow Still not clear the implications of your use case: but in alternative to transaction you could use a multi step, idempotent strategy: for each document make an update marking that the “logical transaction” is in progress, so if it’s ok the 3rd party call update again closing the operation, otherwise you could manage the situation as well
Let me explain once: My application I want to connect multiple social media accounts and I am sending array of object each object having account details required. Now once dataa is jnside server side route I am making a loop on this array and making API call to social media providers to get access token for making requests on behalf of users. Lets say I want to connect twitter FB and instagram account to my app. If I run loop on them it might happen fb and instagram account got connected but twitter did not get connected. So how should I do it.??? If no transactions then how to do error handling on frontend or backend side like if only fb and twitter got connected but instagram failed
It depends from what you need to do in this case, you could simple handle the “connection” error in the backend and perform a single update after all
Обсуждают сегодня