"all or nothing" multiple updates/inserts

Is there a way to perform multiple inserts and/or updates in an “all or nothing” fashion? meaning either all succeed or fail?

Hi @yaron

You can use Do() (here the documentation).
All statements executed inside the Do() statement are executed with the “all or nothing” fashion.

Luigi

@Luigi_Servini already gave you the FQL you need, but to expand a little and offer some meta-guidance, anything that can be submitted as a single expression via a client is atomic (all or nothing). Perhaps you already knew that and were just reaching for the FQL would let you build the expression you wanted, but I thought it worth noting for others who might be passing by.

1 Like

Answered in slack, copied answer here:
Yes, everything in a query is one transaction, use Do or Let to run multiple update statements inside that transaction. From the moment you ‘Abort’ a transaction, all will fail. That abort can either happen due to a faulty update (ref not found or something like that) or you can call it explicitly with the Abort function. Either the whole transaction is executed, or none if it is executed.

PS: try to link forum posts in slack if you ask questions in both the forum as on slack, else multiple people spend time on it which means less work we can do on the product.

Thanks!
Sure, I just forget we are slowly migrating to those forums. Next time I’ll ask it only here.

1 Like

Np, it’s fine to link it in slack, just always make sure it’s clear that the question is asked in multiple locations :slight_smile: