2

I'm following the docs for Firestore here on Aggregation Queries.

I couldn't help but notice that the cloud function solution wouldn't exactly work since it's not idempotent: numRatings is incremented and avgRating recomputed each time.

Though this example could be made idempotent if there was also a separate document being stored for each new rating: you'd add a check if the user has already submitted a rating for the restaurant.

Is there something I'm missing that makes this example idempotent? Or is the point of the example just to show that this could be done in a cloud function?

user1056585
  • 682
  • 1
  • 7
  • 21
  • 1
    None of the examples on the page you linked claim to be idempotent. It's just a simple example. Are you reading otherwise? – Doug Stevenson Feb 10 '19 at 18:19
  • 1
    No, just threw me off a bit that a cloud function example wasn't idempotent (regardless of what the intention to show is). I guess a note around the example clarifying this might help. Thanks for clarifying though – user1056585 Feb 10 '19 at 18:22

1 Answers1

2

Making a function idempotent requires a lot of extra lines of code, which would make the example much harder to understand. You should expect that sample code not to be idempotent, unless it's trying to demonstrate idempotence.

If you have feedback for the authors of the documentation, you are free to give that with the "SEND FEEDBACK" button at the top of each page.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441