Search code examples
firebasegoogle-cloud-firestorefirebase-security

Firebase security rules calulate sum of a list


I have a map like this in Firestore:

ratings:{
    id1:{value:5,...rest of map}
    id2:{value:3,...rest of map}
}

How could i calculate the sum of values (5+3=8) ?


Solution

  • There are no loop operations in the security rules programming model, as those wouldn't scale. So if you want to write a rule against the sum of the ratings, you'll have to store that sum as an explicit value in the document.