I'm using Firebase as the backend to my Flutter project. I need to write to multiple nodes in one transaction. Now I have:
await (_firebaseDatabase
.reference()
.child('user_data').Push().set({"userName":"aaa"}));
await (_firebaseDatabase
.reference()
.child('user_history').Push().set({"userName":"aaa"}));
But these are 2 transactions
, so 1 could end successfully but another one could fail and I want to prevent this.
Another use case is to write to user_data
and update to user_history
. How can we achieve this in a firebase real-time database?
Basically, I want to insert and update at 2 different nodes in a single transaction so that data doesn't get mismatched.