Quering/Filtering by fields in firestore

Thanks. I haven´t tried yet. I want a live scoreboard to want to return all current scores that have been updated in the last hour. Its a bit of a chore as I don´t have a timestamp in that field as yet, so have to roll that out across the app.

1 Like

Adding info:
if you work with one parameter, it works
if you work with more than one, and the condition ANY you get an error Failed to map query parameters
if you work with more than one parameter and condition ALL you get other kinds of errors depending on the parameters you use , the important thing is that i never got the url that is mentioned in the documentation about the indexing.
in the console, i got two urls but both opened an error page.

i would love to have your opinion on this @Mevi , is it possible to make such queries? and how would you do it?
thank you in advance😉

Firestore/Firebase is not my speciality :smiling_face_with_tear:

I would assume it would work with the filter conditionsssss but I haven’t tested them. If you can clearly reproduce that the conditions work if you only have one of them but don’t if you have both, please file a bug report! Sorry I couldn’t be of more help, let me know how more testing goes and if you create the tracker ticket, I might have more time to look into this next week.

Hey, no problem thanks for the response, i think, it would help if you know anyone from the team that specializes in Firebase, so he could provide with a general idea on how to work with filtering.
Because from my search i have come to the conclusion, that neither firestore nor realtime db is easy or even possible to filter with many parameters.(and thats not some kind of AG bug but rather firebase limitation)

I have tried to use multiple conditions and also failed, but since I don’t have too much data to filter, I just used a flow in which I filter data from Firestore Database with single condition then assign it to a pageVar and do the rest of the filtering inside the App itself with the flow functions. This however is not the best practice in my view and I just came across this resource:

Firebase managing indexes

Because Firestore does claim to have support for multiple conditions, but I have to test it later. Will post here any new findings.

2 Likes

Hi, that was my idea at first, but as you said for someone with a big db its not so clever.
as for the indexing, i have read the documentation but couldn’t make it work if anyone has made it work for complex querying maybe can give us some guidance.

1 Like

Hi again, is there anyone, who knows how to create complex queries, (either in firestore or in realtime db, i will choose the one that has the most capabilities in complex querying,)
If you work with that, any help is appreciated.

I´m using Firefoo to query my firestore data but I´m only using it offline. I´m not sure how I would go about getting query results back into my app, but from all I´ve seen in the forum, it seems like its possible.

Firefoo effectively writes the queries for you. Have a look, it might assist or provide some more info to base your decision on.

1 Like

Hi Dimos,
I would be interested to know your progress.
Thanks !

Hi there, unfortunately, i havent found a great way to query multiple values yet and thats the reason i have put my project on a hold.
Actually, thats the only thing missing

Maybe we should look for a JS Query with the Javascript Flow Function ?

// Query with JavaScript using the Firebase Admin SDK
// See examples at https://firefoo.app/go/firestore-js-query
async function run() {
  const query = await db.collection("cars/vqtcRzHbJr4bhgVy4y6Q/items")
    .where("item_name", "==", "redcar")
    .limit(50)
    .get();
  return query;
}

Hi, have you tried that, because i dont know if it works…

Hi Dimos,

What about if you make an get record collection to your database from the logic flow function, and assign the output to a page.var and put this into the assigned value.

SELECT(outputs["Get record collection"].records, outputs["Get record collection"].records[0].fields.country.stringValue == "greece" && outputs["Get record collection"].records[0].fields.price.integerValue == "5" )

Let me know if this works.

yeah, this would normally work, but from what i understand, you are talking about in app filtering the data, the downside doing it this way, is that you make many unnecessary document reads and also this way, doesnt work when you have thousands or even hundreds of documents.

Thats why the best way, would be to filter in the backend and get only the documents you need

Oh, I see, you mean make an pre-query on the backend and then call it from appgyver?

yeah, something like that, actually its something very frequent to do, because in firebase you pay by the document reads, so the logical thing is to only read the documents you need.

1 Like

I will check it detailed, Im so interested on it because I have a lot of read documents right now.

Thanks you so much Dimos.

1 Like

This guideline might help you to implement your Query:

1 Like

I’ll give a shoot to that, thanks stayfoolish.