Home > Software design >  Firebase security rules calulate sum of a list
Firebase security rules calulate sum of a list

Time:07-18

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) ?

CodePudding user response:

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.

  • Related