I have a Firebase function triggered on document creation in the “receipts” collection. The function updates the totalReceipts field in a related document in the “projects” collection using FieldValue.increment.
Here’s the relevant code:
const newReceipt = parseInt(data.amount);
await projectDocRef.update({
totalReceipts: admin.firestore.FieldValue.increment(newReceipt),
updatedUserId: data.userId,
});
Issue:
In one instance, the totalReceipts field was not updated for a document creation, but no error was logged in the function. Two other updates for the same project worked correctly.
Question:
Is it possible for this Firebase function using FieldValue.increment to fail to update totalReceipts without logging an error? If so, what could be the potential reasons?
I reviewed the Firebase function code to ensure it properly handles the creation of a receipt document and updates the totalReceipts field in the corresponding project document. I checked the Firebase function logs but found no errors, which led me to believe that the update should have been successful.
I expected the totalReceipts field in the Firestore document to increment by the amount specified in the newly created receipt. However, in one instance, the field was not updated, even though there were no errors logged. The function worked correctly for other receipts related to the same project, so I’m unsure why it failed in this particular case without any error message.
1