I understand that firebase transactions sometimes reads data as null but then the loop runs again until the value is obtained from server and committed. However I'm facing a unique situation where transaction reads null data and commits the value which I return in case of null. Please have a look at the attached code.
deductTransaction.transaction((current_value) => {
if (current_value != null) {
return current_value - cost;
}
return 25;
});
In the code above "deductTransaction" is the path of the data (number) which I want to update
The above code runs fine in some cases i.e the loop runs again in case null is read and sometimes it just runs once, reads the value as null even if there was some data at that path and then commits 25 thus destroying the original data
P.S: I'm close to pulling my hair out so any help would be highly appreciated