I'm coming to you guys again for help. I have an app, in which you can top up your own virtual wallet from your credit card.
My structure is as followers:
- collection
transactions/{transactionId}
-- contains an owner UID and the top up amount. - collection
users/{userId}/personal/wallet
containing{ funds: 0 }
I am keeping the wallet into a subcollection of personal
info because I don't want other users to see it.
Anyway, I have an onCreate
trigger called walletSync
for new documents under transactions
collection, from which I take the amount and add it to the user's current funds via runTransaction
.
Problem is, the function sometime triggers three times ... for one document. Here's a screenshot. I have logged the transactionId ( which is just one document ) and as you can see, onCreate, is being processed three times, therefore, topping up my wallet with three times the actual value.
Here's my function code, in which I am marking any processed transaction with processed: true
so I can ignore it next time it triggers. As you can see in the logs, that processed_already
message never pops up, which means the trigger does not fetch the new data, next time it triggers.
I am out of ideas here, please advise.
EDIT: Here's my function: https://pastebin.com/PRA7CbxL