skip to Main Content

I have a scenario where each user in my Firebase database can have their own set of recipes, and they can also add recipes from other users to their fav_recipes. Now, I have made changes to an attribute of one of the recipes (For example I change name of recipe), and I need to update all the user’s fav_recipes (with updated name) that include this specific recipe. Here is my firestore schema.

enter image description here

How can I efficiently achieve this in my Firebase database using Swift?

2

Answers


  1. There’s no specific built-in operation to perform such a bulk update. You will have to:

    1. Perform a query to get the affected documents
    2. Loop over the results
    3. Update each document in turn
    Login or Signup to reply.
  2. Single source of truth! You should only have to update in 1 spot.

    You shouldn’t have several copies of the same thing you can use DocumentReference to link favorites to the actual recipe.

    fav_recipes: [DocumentReference]
    

    or something like

    fav_recipes: [Recipe.ID]
    

    So you can query the recipe using an ID that does not change.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search