firebasegoogle-cloud-firestoreaudit-trail

Does Cloud Firestore have an audit trail?


I really like the offering that's Cloud Firestore. But does it have an audit trail?

Why am I asking? While some use of databases is essentially "state" (e.g. multiplayer games), for other uses also the history matters. Also, at times being able to see the history would be useful for debugging purposes (time travel).

So what's the means I would have to ask e.g. "who deleted a value in this document" or "who has touched this doc since its inception"?

Do people use additional commentary documents to do this at the application level, or can I just enable a setting somewhere that would create such a document behind the scene, automatically? (I could then describe access rights just as for any other Firestore document.)

Addons, plugins etc. can also be suggested. I don't have a pressing use case for this right now - just want to understand where Cloud Firestore would fit and where not.


Btw, the Getting to know Cloud Firestore series in Youtube is plain awesome! :)


Solution

  • Edit: 2022-10-25

    As Frank mentioned in his answer, yes, by the time I have written this answer, there wasn't a solution for audit logging. However, when it comes to today, this option is available and it can be also configured based on what you need.

    For a better understanding, I recommend you check the official documentation regarding Firestore audit logging where it is said that:

    Google Cloud services write audit logs to help you answer the questions, "Who did what, where, and when?" within your Google Cloud resources.


    Old answer:

    > **Note:** This answer was correct at the time of writing, but is now outdated. See [this answer](https://stackoverflow.com/a/74154622/209103) for details.

    So what's the means I would have to ask e.g. "who deleted a value in this document" or "who has touched this doc since its inception"?

    Cloud Firestore doesn't store such metadata. If you find yourself in a position in which you need such details, you'll need to create a mechanism to store them. So in case you want to know who deleted a specific value, you should create an array of objects where you should store the UID of the user who deleted that value and a timestamp.

    Do people use additional commentary documents to do this at the application level

    Yes, we usually do.

    or can I just enable a setting somewhere that would create such a document behind the scene, automatically?

    There is no such setting that can be enabled.

    If you need a history version of the document, a possible schema that might help you is in my answer from the following post: