CRUD Querys In AppGyver

How to do CRUD with Firestore API using query filters: where, order by, etc?

Hi @Marcos_Vinicius,
welcome in the forum! There is a search icon on top of the site that helps you to find answers to your questions:

image

In this case it might point you to this Community guide. :wink:

The first thing I tried to do to solve my question was what you mentioned, however, I didn’t find a definitive answer.

I am already able to bring the collections from the bank, this is easy for me, however, when bringing them, I need to filter them so that I only receive collections that have value == “example” for example.

I’ve tried several formulas to do this, but none have worked.

I’m using the Data Variable directly in the formula, then I wanted to get only those collections that have such a value in the field.

But I don’t know how to do that. The Firestore documentation is depressing in this regard.

I also didn’t find video tutorials to help.

I just have to ask for help.

every type of value that I put to filter items from the bank gives an error.

The formula always says that the type is different, or that the data variable is not a list, or that it is not an object.

For example, if I told him to bring the collection that contains the email nelson@gmail.com, is he only supposed to bring it right? However, it brings them all, as if I didn’t enter any query filters.

Miss Where :vvv

Thank you, your questions is much clearer now!

Two remarks upfront:

  • now your question has nothing to do with CRUD Query anymore. As you describe it, you want to download the entire collection and then filter it on the clients device.
  • please be aware of the difference between ‘collection’ and ‘document’. While a collection is a list of documents, a document is an object with key-value pairs. Using the right wording will help you, when searching for answers.

The code in your screenshot works fine. I just tested it in my app. :+1:
If it still doesn’t work like you want it to: Please show the error message, which is displays under “validation”:
image

2 Likes

this solution saved me

SELECT(data.chamado1, IF(item.fields.email.stringValue == appVars.usuario, true, false))

This solution is still temporary for me, because I need to manipulate the data guessed from the bank in the appgyver logic, and not only in the internal components of the app.

Similar to the repeater, isn’t there some way to use some loop to scan all the data and bring back just what I want?

Like for example:

I need something similar to this, you see, only in the appgyver logic…

for (x = 0; x < data.variable.length; x++) {
if(item.email.stringvalue == "example") {
pageVars.example = item.email.stringvalue;
break;
} else {continue;}
}

This is impossible ???

Thank you for sharing your solution!

Regarding your question about a loop:

  • yes, it can be built in the logic flow. I did it before with the help of a pageVars ‘counter’ that starts at zero and a ‘IF-component’, that checks if the counter is still smaller than e.g. the length of a list.
    image
  • BUT, I cant recommend this approach anymore, because in my case it resulted in very slow response time when number of loops increased ( > 100 loops). However if you are sure that you can limit the number of loops: you might give it a try and test it with the max. size of data you expect.
  • → my recommendation is to do these calculations in a formula like you posted above.
1 Like

As in my case I only needed to bring in a single collection from Firestore, so this solution solved my problem.

SET CODE:

SELECT(data.cliente1, IF(item.fields.email.stringValue == appVars.usuario, true, false))

HTTP REQUEST CODE:

STRING("https://firestore.googleapis.com/v1/" + data.cliente1[0].name)

{"fields": {        "senha": {          "stringValue": pageVars.nova_senha        },        "email": {          "stringValue": appVars.usuario        },        "id": {          "stringValue": data.cliente1[0].fields.id.stringValue        },        "nome": {          "stringValue": data.cliente1[0].fields.nome.stringValue        }      }}

Thanks to her I didn’t need to use loops to go through all the collections.

Unfortunately I don’t know a solution for those who need to bring more than one collection on Update.