1

How do i force my rule to know that the new value is equal the value before + 1 ???

tried:

allow write: if request.resource.data.counter == resource.data.counter + 1

what i'm doing wrong?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
eeerrrttt
  • 549
  • 2
  • 7
  • 24
  • 1
    How are you testing that this rule doesn't work the way you expect? What's the entire rule, and what's your code to exercise it? – Doug Stevenson Mar 05 '19 at 21:28
  • That rule looks fine at first glance. As Doug asked: what code are you using to test this? – Frank van Puffelen Mar 06 '19 at 04:52
  • Lol guys, i'm just trying to increment my database. I have a counter of commentaries, for each commentarie, my total_commentaries is updated by a value equals -> old value + 1, which is what i'm passing to the rule. But i get block. Before putting the rule, it was allow write, after putting rule, got blocked, so yes, a simple test – eeerrrttt Mar 06 '19 at 15:05
  • Please avoid using security rules for incrementing counters. Instead, use Transactions to update data and keep it consistent. https://firebase.google.com/docs/firestore/manage-data/transactions – MichelDelpech Mar 07 '19 at 20:59
  • Whaat?? Kkk, security rules are just to protect fields updated by transactions. – eeerrrttt Mar 07 '19 at 23:26
  • here is my post - https://stackoverflow.com/a/62368061/271450 – Jonathan Sep 17 '21 at 04:00

0 Answers0