问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/54619473/firebase-cloud-function-idempotency-in-docs