Firestore get function is not working, “is not a function” error

  Kiến thức lập trình

I’m new to firestore cloud functions. I’m trying to write a function that based on the change of one collection should be updated the data of another collection. I’m facing an issue on using the get function. It return “Exception from a finished function: TypeError: aggr_ingredient.data is not a function”. Can you check my code and point me out what I’m doing wrong?

Thanks,
Giuliana

Below my code:

// When any field on any document in course change (added or updated), the aggregate ingredient should be updated
exports.updateAggrIngr = onDocumentWritten("/course/{courseId}", (event) => {
  // Save the data after the update/creation courseid
  const v_recipeRef = event.data.after.data().recipeRef;
  const v_servings = event.data.after.data().servings;
  const v_userRef = event.data.after.data().userRef;
    // Take the recipe information from the course changed
  return v_recipeRef.get().then(recipe => {
        const ingredients_LLM = recipe.data().ingredients_LLM;
        for (var i in ingredients_LLM) {
          console.log("1) Processing ingredient: "+ingredients_LLM[i]["name"]);
          var v_ingr_name=ingredients_LLM[i]["name"];
          var v_ingr_amount=ingredients_LLM[i]["amount"];
          var v_AggrIngrRef=ingredients_LLM[i]["AggrIngrRef"];
          // Increment total amount and partial amount of the ingredient
          console.log("2) Increment total amount and partial amount of "+ v_ingr_amount+" for "+ v_ingr_name);
          db.collection("aggregate_ingredients").where("name","==","Farina").get().then(aggr_ingredient =>{
            console.log("name: "+aggr_ingredient.data().name+ ", userRef: "+aggr_ingredient.data().userRef);
          });
        }   
    });
});

Recognized by Google Cloud Collective

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT