How can I implement firestore database trigger (onCreate, onUpdate) with Cloud functions for firebase gen 2 ?
As in Firestore cloud function gen1 we can use Cloud firestore database triggers, But how can we implement this in Firestore cloud function gen 2
As mentioned in the documentation, Cloud functions gen 2 do not support Cloud Firestore triggers at the moment.
You'll have to use Gen 1 functions if your application rely on Firestore triggers.
Related
I was looking at a few ways to export data out from Firestore without using export (expensive operation in the long term as it doesn't support incremental backups) to use in BigQuery and Data Studio.
1) Using Google Pub/Sub.
This will probably require function to both write to pub/sub and then another to trigger to BQ.
2) Using Cloud Functions to trigger from an onCreate event to write directly to a BigQuery dataset and table.
(This is using table.insert)
What would the advantage be to use Pub/Sub - other than it would appear that it will cost more in the long term?
Or is there another way I am unaware of to do this?
I'm new at this. Some advise and pro and cons of the above scenarios are much appreciated.
The official solution is here.
In case of using Cloud Functions to trigger from an onCreate event, what will you create? Create File on Cloud Storage or create Firestore Document?
I think that in case of using Cloud Functions you should use PubSub trigger.
I recommend asynchronous architecture like Pub/Sub. Because rerun is easy and the scope of influence is limited.
I developed sample is here. I'm using Cloud Scheduler not cron.yaml. The cost of Cloud Scheduler is here.
(If you want) Export Firebase Authentication users to Cloud Firestore Collection. Use Firestore, Cloud Functions(PubSub) and Cloud Scheduler.
Export All Cloud Firestore Collections and Specified collections to Cloud Storage. Use AppEngine and Cloud Scheduler.
Export Specified Cloud Firestore Collections to BigQuery( as Partitioned tables). Use AppEngine and Cloud Scheduler.
This documentation link for App Engine outlines an example where app engine listens to a RealTime Database reference.
I was wondering if
This can be done equivalently with Firestore using .onSnapshot
Whether I can specify wildcards in the reference as I do with cloud function triggers
Yes
No
There are no wildcard listeners with the Firestore SDK. Cloud Functions is responding to events generated by Firestore, which is very different than how a listener in the SDK works.
According to this documentation, you can create a mock DeltaSnapshot for firebase realtime database. But I am trying to test a firebase function using firestore, and here the event has this type:
event: firebase.Event<firebase.firestore.DeltaDocumentSnapshot>
So how do you mock this event, so you can unit test functions utilizing firestore triggers?
I want to connect my laravel app with google cloud datastore and want to use same data for android and ios application, for that i want to use firebase.
Can any one have idea that how can i access my google cloud datastore's data in firebase ?
You could try using Cloud Functions for Firebase to fetch/query data for you using the Node.js client libraries.
Documentation:
Google Cloud Node SDK for Cloud Datastore
Cloud Functions for Firebase
You could also try Cloud Functions for Firebase and/or Firestore DB instead of Google Cloud Datastore.
Firestore is the next evolution of Firebase (Realtime DB) with better support for scaling & data modeling + offline data management.
As I know currently Cloud Functions doesn't support triggering functions from Firebase.
For now I'm planing to use an basic Engine instance to trigger the functions based on the queue.
Is this the right way to go? or should I trigger the cloud function directly from the clients device after the data is inserted in the db?
thank you
Cloud Functions for Firebase was just launched today! You can use the SDK to trigger cloud functions from your Firebase database, storage bucket, authentication, and analytics events. https://firebase.google.com/docs/functions/