Query Firestore Collection against a List of Matching Values

Hi all…

I’ve learned a lot by reading questions/answers from others in this forum, but have not been able to find this answer here. Apologies if it has been asked before.

I have a list of values in my app and a collection in Firestore that I want to match a particular field (goal_id) against the list of values in my app ([3, 5, 8, 25, etc…]). I can create a data variable that filters based on a single value, but am not sure how to create a filter based on a set of values (e.g. the equivalent of an “in” rather than an “=” query in SQL). I don’t want to query all the documents in this collection and filter as it could be a very large set eventually. Ideally, I’d like to just query for the documents that match my list.

Does anyone have a suggestion for how I would do this within Appgyver/Firebase?

I did find this documentation in Firebase (Cloud Firestore Now Supports IN Queries!), but have been using the Firebase integration of AppGyver which doesn’t have “in” as an option as far as I can see. But perhaps there is a way to do this with a formula? Or do I need to use the Rest API integration with Firebase?

You can use these operators to query Firestore (the ‘IN’-operator is one of them):

To build the query for your Firestore-database, I recommend to follow the steps in this guideline:

1 Like

Thanks! That’s really helpful. Look forward to trying this out!

Thanks for your help here. I got this to work following your instructions. Not sure if this is the best way to do it, but I had some issues constructing the object and changing the parameters dynamically and I found the best way to do it was to create a page variable that was an object with the structure of the JSON structuredQuery and then I could edit that object and post the entire object to the URL. I wish I could do >10 items at a time, but it’s not a big deal to run the query a few times if need be. Very much appreciated and I hope this helps others.

1 Like