Firebase - Targeting Specific Firestore Document Field with Cloud Functions

前端 未结 1 1643
后悔当初
后悔当初 2021-02-20 17:58

When using Cloud Functions with the Firebase Realtime Database you are able to target a specific field with a cloud function. For example, given this JSON structure, I could tar

1条回答
  •  一个人的身影
    2021-02-20 18:10

    You are correct, due to the different data models Cloud Firestore only allows you to trigger Cloud Functions on document level events rather than field level.

    One method is to store email in a separate document (e.g. in a subcollection called Email), so updating email is tye only change that will fire. This does require you reading an extra document each time you need the email though.

    Another similar method is to still have it in the same document, but also write it into the subcollection as a second write to trigger the function. Use email as the doc I'd and have a timestamp field in the document to make it easy to clean up the old document ( select oldest email doc to delete, maybe even in the function)

    0 讨论(0)
提交回复
热议问题