I want to update two fields in a document in a collection called recipes and i used the batch update to do it:
let recipeRef = db.collection('recipes').doc(`${recipeId}`);
let batch = db.batch();
batch.update(recipeRef, {ratingsCount : admin.firestore.FieldValue.increment(1)});
batch.update(recipeRef, {totalRating : admin.firestore.FieldValue.increment(snap.data().rating)})
return batch.commit();
And I have a trigger function on the recipes collection like this:
exports.RecipeUpdated = functions.firestore
.document('recipes/{recipeId}')
.onUpdate((change, context) =>
{
//code
});
My question is as there are two updates in the above batch, will this also trigger the onUpdate function twice Or since the batch writes completes atomically, trigger will be called only ones? I want the trigger to be called only one time.