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.
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.
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:
- 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.
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM