0
votes

I am trying to write a Cloud Function in Node.js.

The function requires to return a Cloud Firestore document data as a json form.

I have read the document, where I could find Cloud Functions can be triggered on Cloud Firestore events such as onCreate and onDelete.

However, beyond these event cases, where the documents are not updated nor deleted, I would like to know if this could be done using functions.firestore object.

Is it possible? Or should I just use the REST API for Cloud Firestore and create sth like functions.https.onRequest. If your choice is the latter how should this be implemented in Flutter?

1
To clarify, you want to know if you can get a document from firestore using Cloud Functions without using a document event listener (onCreate/Write/Delete/Update) ? - S.Ramjit
What is your exact goal from a functional perspective? Can you please explain it without mentioning any Library or API, but just explaining what you expect to happen from your front end. - Renaud Tarnec
@RenaudTarnec Sorry for the late reply, I want to achieve a request response function which sends a json depending on the user's status. In the presentation layer, the user will be notified with an ideal data which matches their current status. - Johntopia
@S.Ramjit Yes that is correct. - Johntopia

1 Answers

2
votes

It sounds like you want to use Cloud Functions to create an API that your app can call to get back some data from Firestore. This is indeed possible, and in fact quite common.

In this case you'll implement either a so-called HTTP function or a Callable Cloud Function that performs the necessary interaction with Firestore through the Node.js Admin SDK.