Firestore allows me to add a field with the type "Reference" to a document. It's a reference "link" to other documents inside the Store.
While I imagine this is very handy, I'm missing documentation on it.
I'm having some trouble saving a reference from a Firebase Cloud Function for example.
On the client side, I just send a regular "ref" object via the client SDK and it saved the document-reference. In nodeJS (cloud function), I get an error that the object is too deep.
What's the proper way to save a field with the type reference from the admin SDK (and/or JS client SDK)?
The Firebase Admin Node SDK was updated today and fixes this problem. https://github.com/firebase/firebase-admin-node/releases/tag/v5.4.2
Related
Using Google Firebase Functions as a backend of the small application.
Functions are accessing to the Firestore and Realtime database, therefore they need service account credentials file.
On the other hand, I'm trying to automate the deployment of the functions using Github Actions.
Currently I places the credentials file inside the repository. I know that it's not secure.
What is the proper way of storing service account credentials file in this case?
Firebase projects, are, in effect, Google Cloud Platform projects.
More specifically, when you create a Firebase project, an associated Google Cloud Platform project is created for it.
Therefore the process for storing credentials is the same as in Cloud Platform, which is to say in a file, somewhere relatively safe.
This file should be accessible to your Function if it is required, and should either have its path specified as part of an environment variable or explicitly declared in code.
You are already storing it the proper way, because the improper way would be to insert the contents of the JSON file directly into code.
To prevent others from seeing the contents of the JSON file, simply set the respository as private.
i have a firestore database firestore database structure
How do I write a cloud function to send a cloud message to all the app users when one of the fields in the firestore database is updated? in my case when the price of the price_change_pct field goes below the value -1 ?
You can refer to the link, where as stated:
You can invoke a Cloud Function from the Flutter app either through HTTP or a database trigger and let the Cloud Function do the work for
you. Inside the function use the Firebase Admin SDK and send messages as you wish.
In the Documentation, the whole description related to Firebase messaging for the multiple devices has been explained briefly.
You can also refer to the stackoverflow answer and case where the community resolved a similar issue.
I tried to extend my Firestore to Functions and triggered onCreateat Firestore saved.
I want to save each UIDs by Firebase Authentication (By Admin SDK).
This Collection is made automatically by webhook
Each Documents include Personal Informations more than 1 people (2 in there).
But I got this Error ยป "admin.auth.getUserByPhoneNumber is not a function"
Is anybody there to make Example?
In the context you are trying to use it, admin.auth is a helper function to get the Auth object of the default application initialized by admin.initializeApp().
Change your line so that the admin.auth() function is called.
admin.auth().getUserByPhoneNumber(/* ... */)
// ^^
Is it possible to reference user objects in Firestore like a regular document from collection ? I've created a sample of fake users for test in the Authentication section, and I'd like to reference them in a collection.
Their is the reference field :
The id seems correct, however calling a db.doc() with this reference as a parameter returns an empty document (snapshot.exists returns false).
The database 'users' isn't present in my collections since it is handled by Firestore authentication system, but I was wondering if their was a way to access it, similar to regular documents.
You seem to be mixing up two products in the Firebase platform:
Firebase Authentication handles user sign-in.
All information about these users is stored in an internal database,
that you can only access through the Firebase Authentication APIs.
Cloud Firestore stores data that you put in it.
Firebase Authentication does not automatically create any user data in Firestore when a user is created. If you want such data in Firestore, you'll have to create it yourself, either in your application code, or in Cloud Functions in response to the user-created event.
Within Cloud Firestore there is no type that is a "reference to a Firebase Authentication user". But if you store user-specific documents in Firestore, you can use its Document Reference type to reference those user-specific documents.
Is there a way to modify/add metadata fields to an object uploaded to Firestore Storage in the onFinalize trigger function? There is documentation on how to perform this operation on the client side but not on the server side.
There is plenty of documentation for the server side libraries. If you're deploying code to Cloud Functions using the Firebase CLI, that means you're probably using the Cloud Storage node SDK. The API documentation for that is here, and the general documentation is here. In the general documentation there are even plenty of examples to get you started. One of the samples is called "storage set file metadata".