0

I have 2 collections. One of them is named "USERS", and the other one "MATCHES". USERS, can join in the MATCHES, appearing the avatar of the user who has joined in the match. The problem is that when the user changes their avatar image after joining in the match, the match avatar doesn't changed, because the match has the old avatar.

The avatar is saved as Base64 in Firestore, but I will change it to "Storage" in the near future.

I have been trying to set the reference, but that only gives me the path.

If I have to do a Database Api Call for each match which is joined the user, maybe I have to do 20 Api calls updating the matches. It can be a solution, but not the best.

Maybe the solution is in the Google Functions? I'm out of ideas.

Zoe
  • 27,060
  • 21
  • 118
  • 148
tzonGoza
  • 361
  • 3
  • 10
  • what about keeping the avatar value on the user collections, and update it just there... then when loading the match, you just query the users' info of that match and then u have the avatars up to date available – andresmijares Jun 21 '19 at 19:23
  • Well, that suppose that I'll have to do even more queries, because the match can have up to 5 visible players, before entering in the detail. Reading the Frank's answer, I see that the best solution is to change the avatar in all the matches at once. – tzonGoza Jun 25 '19 at 21:10

1 Answers1

0

Maybe the solution is in the Google Functions?

Cloud Functions also access Firestore through an SDK, so they can't magically do things that the SDK doesn't allow.

If you're duplicating data and you update one of the duplicates, you'll have to consider updating the others. If they all need to be updated, that indeed requires a separate call for each duplicate.

If you don't want to have to do this, don't store duplicate data.

For more on the strategies for updating duplicated data, see How to write denormalized data in Firebase

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807