Ad

How To Get Notification When A Field Is Created Or Deleted On Cloud Firestore

I have 3 collections: Therapy, Users, and Transaction at the top level. enter image description here

Below Users there are Customer and Therapist. The customer will created a Transaction with the selected therapist.

When customers order something, the field is created and the therapist will get a notification. Both the Therapist and Customer may cancel the transaction, which will mark the field as deleted. Upon deletion, both will receive notifications.

How i can do this?

I can't provide sample code since I don't know where to start.

Ad

Answer

Cloud Firestore triggers provide a mechanism for handling Firestore events.

With Cloud Functions, you can handle events in Cloud Firestore with no need to update client code. You can make Cloud Firestore changes via the DocumentSnapshot interface or via the Admin SDK.

In a typical lifecycle, a Cloud Firestore function does the following:

  1. Waits for changes to a particular document.
  2. Triggers when an event occurs and performs its tasks (see What can I do with Cloud Functions? for examples of use cases).
  3. Receives a data object that contains a snapshot of the data stored in the specified document. For onWrite or onUpdate events, the data object contains two snapshots that represent the data state before and after the triggering event.
Ad
source: stackoverflow.com
Ad