I have these Firestore Security Rules. I need to check if the 3 amounts "redAmount", "greenAmount" and "blackAmount" added together exceed the user's balance. If so, the update should be rejected.
function checkSums() {
return futureDocument().redAmount + futureDocument().blackAmount +
futureDocument().blackAmount <= getUserDoc().amount;
}
But this functions fails if one of the amounts is undefined => not set, which I want to be 0, but I can't. Any ideas on how to fix this?
This problem is not solved by referencing to the "How to validate that a field is undefined" question.
in
operator is best for that. See stackoverflow.com/questions/53458413/… So something like(redAmount in futureDocument() ? futureDocument().redAmount : 0)
. – Frank van Puffelen"redAmount": 0
). – Frank van Puffelen