Skip to content
Advertisement

How to do CRUD operations on a firestore DB from a cloud function? (Node.js)

I use a cloud function as a webhook receiver, so every time I get a webhook I want to update firestore with some data for example. I don’t get how to use firestore in my clound function.

I tried this:

JavaScript

All do not seem to be able to initilise this. I also tried:

JavaScript

Advertisement

Answer

As explained in the documentation, the following should do the trick:

JavaScript

Then, to interact with the Realtime Database in an HTTPS Cloud Function you should do along the following lines:

JavaScript

Since you tagged your question as google-cloud-firestore, note that in order to interact with Firestore in an HTTPS Cloud Function you should do as follows:

JavaScript

I recommend you watch the following official video.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement