Complex Array List on Firebase

Good Day Everyone!!

I am not a techy and trying out App Gyver for the first time. I want to add some personal details to my firestore collection as the data. I am able to do it as well. But the problem is all the time I input the details automatically make a new document with same schema on firestore database.

I want to store data there according to the user id… what I mean is when the same user add the data second time it should come under the same document ID with second Index (eg: Index 0, index 1, index 2…).

When ever a new user with different system add the input, it should store as new document with same schema. Hope you got my point and help me to solve the issue. Some scree shots bellow.

If the same user Add details second time, It should come under purple marked box with index 1…so on. If the the new user added details should comes in green box as new document.


This is my Input field.


Mapped resource record.

Help me on this please.

It is easier to learn how it works, if you reduce complexity first. Therefor I recommend to break your proble down into 2 steps and then solve it one after the other.

  1. Updating an existing document in Firestore:
  • As you are currently using the “create record”-flow function, you create a new record every time the code is triggered. Instead of ‘creating’ you need to ‘update’ the existing document. For Firebase you need to use PATCH, like described here in the forum: FireBase Firestore Custom ID (Post and Patch)
  1. Extend the existing document dynamically:
  • to add fields to the document rather than to overwrite old fields, you would need some logic like:
    a) GET the existing document
    b) combine the new data with the existing document, in order to get a new document
    c) use the new document to PATCH the document on firestore.
2 Likes

Hi @stayfoolish

Thanks for your time. I don’t want to update the same record with index 0 (purple box) whenever I input some data in the app. I want to add new record under index-0 with new index-1, if the user is same. If the user is different it would be a new document with same schema like in green box.

Two doubt to clear here,

  1. How make it possible?

  2. Which is the unique user ID?

It would be great and helpful if you elaborate your second point " 2. Extend the existing document dynamically: ".

Make my concept very simple to you… I want the user to to add their address details, they can add it directly by putting their details in the field and submit, it will be added and stored as a document in firestore. If the same user want to add second address, it should come under the same document with second index( ex: index-1) not a new document. And later in app user can choose which address that he want to show.

Thanks

Hi @Bravo_Moossa,

your description and screenshots are very specific and I understand quite well, what you like to do. I am happy to help; just keep in mind that in the end you need to learn to do the coding yourself.

Regarding the section “Extend the existing document dynamically”:

From you screenshot I can see, that you are combining an ‘firestore-array’ with a ‘firestore-map’. That is a rather complex document to start with. I recommend to train yourself with a document with less complexity first.
The formula functions I expect you are going to need in order to re-built your document are MAP() and SET_KEY().

Regarding the user ID:

you can use the flow function

or you use a HTTP request according to this documentation:
Using the REST API | Identity Platform Documentation | Google Cloud

Thanks @stayfoolish for your time…

Am keep trying to learn what you mentioned above still I couldn’t figure out my problem…

Could you please help me on this regard with formula and function. I have been running behind this from a week before.

In my firestore, addDetail is an array list with firebase map field in it.

It would be nice to see the progress in your effort and thereby an evolution of your question.

From my perspective there is no real difference between your first and your latest post in this thread. I am not seeing that you are making use of the recommendations I gave you at the beginning. That would mean that you break down your problem into smaller steps and solve them one after the other. As a consequence you would progress your code and at get to specific questions along the journey.

have you accomplished it yet? Is because I’m exactly looking to do what you want

What you need to accomplish?

The document ID to userId or the array list from the above

You should use HTTP Request flow function and Patch method with Bearer idToken (depends your db rules) header. And add ?updateMask.fieldPaths=addDetails to your HTTP Url. Send request body with a formula like this:
{“addDetails”: {“arrayValue”: {“values”: yourPayloadArrayObject }} }}

This way you will update your document without replacing it with new data. This is the method which works for me.

1 Like