Query Firestore Database: Help

@Vignesh_Rajendiran; @Bruno_Oliveira; @Kaushik_Bhattacharya

I’ve been stuck in a particular problem for the past few days, and it has been consuming a lot of my time. The best part is, it seems so obvious and intuitive, but somewhere, something is going wrong

Details of the Problem:
I’m trying to query firestore database
As everyone knows,Appgyver doesn’t allow to use ‘repeat with’ alongside the POST method. So, I’m forced to use the HTTP flow function to get the response.

The problem:
=> Since I’m using the HTTP flow function, there should be some variable where the responses are stored so that I can use ‘repeat with’ property
=> The guides i read on this forum suggest me to use a ‘data variable’ for this purpose. But according to my understaning, a data variable is used to import a ‘data resource’ that is already set on appgyver’s data tab

Nutshell
So basically, I’m trying to query firestore database and use the response with the repeat with porperty.
For example, a query to find all users under the name of VIGNESH. Let’s say there are 10 users under the name. Firestore db responds with 10 documents. How should i display it to the user?

NOTE FOR THOSE WHO ARE LOOKING FOR A TUTORIAL

The following thread is an interaction between myself and @Bruno_Oliveira. Through the round of stupid questions I posted him, I hope this thread serves as a clear and concise guide for the beginners out there. I’ll soon put together a community guide where i explain the entire process with screenshots. I’ll do it, once i figure out the correct way to map data. For now, enjoy this, and all the best :))

Again: the OUTPUT of your HTTP POST must be bound to a data variable or page variable with matching schema or of the type “any text”. Use, for instance, the SET DATA VARIABLE flow function and bind it with formula editor.

To get the schema rather automatically, you can configure a DATA RESOURCE for the same source you’re querying and test it. Click “set schema from response” and then the data variable will have compatible schema to accept the query response.

On the other hand, setting the schema of a page variable is entirely manual: you must add object per object, property per property and its tiresome. If you define it as “any text” it will accept any parsed json string from your HTTP POST response OUTPUT. But you won’t be able to reference it the usual way in formula editor because composer won’t know the schema and you must reference it blindly, knowing what the schema of the parsed json actually is.

Hope this helps. But you’re clearing getting repetitive answers for repetitive questions. Maybe you need visual feedback (screenshots). Others are more fit to provide it at the moment.

Well, I don’t understand what you mean. “Repeat with” only accepts formula editor binding or data/page variables. That the data comes from GET or POST or ON STORAGE or whatever is irrelevant. It must be SET TO A DATA/PAGE VARIABLE. (Or manually typed inside formula editor, of course)

1 Like

Hi, so I understand what you mean. One last question…
firestore db sends response inside the ‘documents’ array. Is there any way I can access it using formula?

For example, if i want to get the category.stringvalue which is inside the documents array, what should be my formula?

Yes, likewise:

Composer formula editor won’t know the schema of the response but we do: it’s item.document

You’re confusing DATA RESOURCE configuration with DATA VARIABLES.

Bruno Oliveira

First of all, thank you so much for taking your time to help newbies like me. You took screenshots for my understanding, nobody goes all the way to do that. I mean it.

I still have a few questions till I get this one cleared.

QA: You mention about creating a data variable. AppGyver doesn’t allow me to create data variables without setting up a data resource. So, like you adviced, i setup a data resource with the configured to GET COLLECTION and set the schema from the response. If I’m right till this part, how can I go about binding a data variable since a data variable is nothing but a reflection of the data resoruce you set up? If I use the data variable with the repeat with property, i get the data from the URL that i configured in the DATA tab and not the intended firestore response that i stored from a HTTP flow funtion. Am i missing something here?

Q2: Can you tell me how to access the category field which is of type string? Based off the screenshot you sent me, I feel like it should me item.document.category.stringValue, right?

Thank you. I’ll get everything clear if you could give me a brief step by step instruction on setting up data variable and mapping the outputs. I’ll forver be grateful :)))

Actually, creating a data variable with the schema borrowed from any specific data resource does not require populating it with the GET COLLECTION from that resource. You can just delete all the flows that, by default, come along with creating the data variable and populate it with any other data you’d like to fetch or otherwise input, only making use of the predefined schema.

If from firestore, then it should look like item.document.fields.category.stringValue

But why reference and filter that so early on, when you’re storing data in a data variable? Why not populate the data variable with all the fields and point to what you need only later?

I thought the MAP formula you gave me was used to populate the data variable.

I have deleted the default data variable logic after setting schema from response like you said

This is my screen now:

The http flow function fetches a friestore db collection. Let’s say i wanna populate the category.stringvalue… how should i do that?

According to my understanding, this is the formula I should be using:

Is this correct?

First of all, in your first screenshot, I would suggest using always formula binding instead of CUSTOM binding or the integrated MAP binding.

Secondly, why would your data variable be one single text string? If that is what you wish to store, use a PAGE or APP variable instead.

If that formula doesn’t work, try MAP(outputs[“FETCH UPDATED KOMPROS”].resBodyParsed, item.document.Category.stringValue). Still, the output could be an entire list instead of a single text string. Then you would need other formulas to convert the list into the desired value. Explore composer formulas like FIRST_ITEM, PLUCK, LOOKUP, etc.

In the above screenshot, i clicked on the binding that was corresponding to the ‘category’ field from the schema i stored. You suggested using a data variable as it’s less hasslesome, so I assumed you implied using the integrated map binding.

All I’m trying to do is, get the response from the HTTP component and map it to the data variable (which has the schema now)

My progress so far (thanks to you) has been setting the data variable schema. For the next step, I need to somehow populate all the fields to their corresponding values.

Intuitively, I can think of 2 ways to do this:
first: use the integrated MAP to select the values (eg: map the op of category to the category field from the schema)
second: use the formula.

You suggest using a formula. I assume, what you’r suggesting is this:

If it wouldn’t take too long, can you please rewrite the formula for my use case, so that I can use it as a starting point? [IM PASTING THE FORMULA BELOW]

FORMULA:
[{name: "", fields: {id: {integerValue: ""}, price: {stringValue: ""}, category: {stringValue: ""}, delivery: {stringValue: ""}, "product_name": {stringValue: ""}}, createTime: "", updateTime: ""}]

What am I trying to do? [In a nutshell]
=> Get the list of documents from firestore and populate it in this data variable so that it can be used with the ‘REPEAT WITH’ property

Thanks!

No, if the data variable schema already exists and is the same as the response, you don’t need to write the json string all over again. Just

MAP(outputs[“FETCH UPDATED KOMPROS”].resBodyParsed, item.document)

That is, provided the response comes in “document” (I always forget if that’s firebase structured query or GET FROM STORAGE).

The above will match all the fields and create the array of data according to the response.

Done! I did this. However, I’m not sure if it worked. This is my composer:

First the button ‘send request’ sends a http request to the firestore collection using the HTTP FLOW FUNCTION and the output is set to populate the data variable that you supplied.
I did this, with the understanding that, once the data variable is populated, the results will instantly be reflected on the screen.

However, I don’t see the repeated list in preview portal which suggests that it might not have worked.Your thoughts?

PREVIEW PORTAL:

FORMULA TO POPULATE DATA VARIABLE:

You should review your structured query. Composite filters usually require previous firebase index setup. You can link a toast to the output to read it. It probably isn’t coming out as OK 200. Either that or your data variable doesn’t match the schema of the response. You should be able to investigate and find out on your own from there. Good luck.

Thank you so much for your continued support. I know that this question was posted multiple times (merely out of desperation) and a very few came forward to help me.
In the slim number of volunteers, only you stayed along to guide me through the whole process.
Despite staying a 1000 miles away in Brazil, you responded to my messages, while you could have easily ignored it.
Infact, I’ve developed a routine over the past week where I open the forum just to see that grey circle, hoping that you would have replied >>

I’m indeed limited by my ability to send my immense gratitude through text messages. But I mean it

Thanks again :))

PS: The response array is under the name ‘documents’ not ‘document’. Also, being experienced for several years with firestore database, I can assure you that I know of its intrinsic workings including indexes. In the above examples, it is not even a firestore query. I just wanted to test how this works using a regular collection, so yes, the response is 200 OK.
I’ll learn to map it soon, for now I’ll get outta your hair :))

BYE!
[DHANUSHKKAR_H]

Uhm… I believe “documents” with the GET method. “document” with the runQuery POST.
But for the GET method without filters you are better off using the built in GET COLLECTION flow function, are you not?

I just wanted to get familiar with how this works. So,i used collections as a starring point, since I know for sure that the endpoint works
just wanted to add that, I cleared the entire logic of the data variable like this:

Do you think, this has something to do with my failure to get this working?

UPDATE:
I got this working for a singular data record (without map) here:

So,i think the problem lies with using the MAP function

UPDATE 2:

Omg, finally:

This is the formula that works for me:
outputs["HTTP request"].resBodyParsed['documents']

I used the formula to set the data variable without the MAP and it finally worked!!!

Again, thank you so much!! Maybe the MAP formula only works for queries

1 Like