Search code examples
firebasegoogle-cloud-platformgoogle-cloud-firestoregoogle-cloud-functionsgoogle-cloud-logging

Trace who updated a Firestore document in a Cloud Function


I encountered a situation in which one of my Firestore docs changed unexpectedly.

I have a Firebase Cloud Function which listens to those doc updates. I have a trace id of a log from that function. Is it possible to find out which userID or firebase function updated that doc on that specific event?


Solution

  • By default a background Cloud Function triggered by an update in Firestore does not know which user updated the document.

    The only way to know that would be to have a field in the document containing the last user who updated the document. In other words, in the front-end code you would get the user uid and add it to the data/payload object passed to the updateDoc() method.