I have 3 collections: Therapy
, Users
, and Transaction
at the top level.
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.
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:
- Waits for changes to a particular document.
- Triggers when an event occurs and performs its tasks (see What can I do with Cloud Functions? for examples of use cases).
- Receives a data object that contains a snapshot of the data stored in the specified document. For
onWrite
oronUpdate
events, the data object contains two snapshots that represent the data state before and after the triggering event.