I’m trying to push all my player variables that are in a structure into Firebase
What is the expected result
Globally save my stats
What is the actual result
I’ve found two methods, WRITE A FIELD, and WRITE A DOCUMENT
Writing a field is working, but not efficient, i have to multiply the calls and it will be hundreds.
Writing a document seems quite nice on paper, but i can’t make it work, i don’t understand what is expected as “variable” ? so i got errors
As far as I know, WRITE A DOCUMENT does not help to save more things at once and the action has never worked for me.
In most cases the best solution is to convert the main structure variable to json (expression) and save it in one field. (non-existent documents are created automatically)
When loading, use the json action back into the structure variable.
A document is a structure variable, it is a collection of fields and values. This error means your “temp_user” is not a structure variable. Make sure you pass in a structure variable.
I would recommend against that, as it is bad for performance, bad for observability & control (you cannot easily visualize and edit your data in the firebase console), more expensive (as information is stored in an inefficient way leading to more storage consumption), it makes it impossible to use query filters with the database fields, and maybe most importantly, you cannot have security rules this way.
The “write” action will create or overwrite an existing document, replacing a previous document with the same name. To make changes to multiple fields of a document at once without touching the other fields, similarly to the behavior of the “merge” option, use the “update document” action.
I thought you often recommended JSON for this.
Should he really use a separate “Write a field” and “Get a field” action for each of the hundreds of values? Maybe I’m misunderstanding something, but that certainly wouldn’t be good.
It sounds like he only wants to load everything once when the game starts, not individual things while playing.
I wouldn’t generally recommend using the actions to read or write a single field, as they unnecessarily consume more reads and writes in the Firebase quota, and are less efficient.
My recommendation is to fit all the data you need in a single structure variable and to write the entire structure variable as a document in Firestore, not as a JSON string, and to read the entire document as well when you need to access it with “Get a document from Firestore”.