Filtering Firebase Collections by Record Name

Hey all,

I am having some trouble filtering Firebase data. For context, I have an app where users can post a document to a firebase collection with 5 or so fields. I want to filter by name. I am using Firebase, and I use the API Data resource instead of the connector due to my familiarity with it. Currently when the page loads, I use the standard Get Collection flow and repeat the documents from the collection. I want to enable the user to type in a name (pageVars.name) and click a button and perform the same get collection, but limit the results to the name from the collection below. I have tried the no code powerup from Appgyver on YouTube as well as a few help articles on these forums but cant get this to work. I was hoping someone may be able to provide a formula I could use for this.

I have tried the following and can’t find anything that works:

Different variations of: SELECT(outputs[“Get record collection”].records, CONTAINS(outputs[“Get record collection”].records, pageVars.name))

FIND(outputs[“Get record collection”].records, outputs[“Get record collection”].records[“”].fields.name.stringValue == pageVars.name)

FIND(outputs[“Get record collection”].records, item.name == pageVars.name)

FIND(outputs[“Get record collection”].records, item.fields.name.stringValue == pageVars.name)

Here is the firebase collection:

Here is the item in repeat which works as expected without filtering:

Can you explain? I don’t understand.

I wish I could give a quick help serenely but I’m in a state of panic because of another Appgyver Save crash that’s losing days of work, again and again and again, and you are using the less popular/recommend firebase data resources setup.
Anyway, maybe try:
SELECT_BY_KEY(outputs[“Get record collection”].records, "name", pageVars.name)

If still fails:
SELECT_BY_KEY(FLATTEN(outputs[“Get record collection”].records), "name", pageVars.name)

Well, on a different approach, in that case I would use a firebase structured query via REST HTTP with a GREATER_THAN_OR_EQUAL_TO operator and a limit of 10 or 20 items.

Then the results fetched would be only similar to whatever the user typed. That, I believe, would be de closest equivalent to, like you said, “getting a collection” with limited (filtered) results.

As for

I believe the first argument of CONTAINS should be specified in a particular field.stringValue, for a list of records is probably not compatible with CONTAINS. Or is it?

There are multiple things to consider here.

  1. Do you handle case sensitive search or not. (I mean do you want to handle it :sweat_smile: )

  2. Do you only do exact match or include some sort of fuzzy search solution?

  3. As for the first question you might want to duplicate the “name” field in your firebase records and make that a lowercase when user creates the name, so that you can use that for search. This way simplifying your problem.

  4. Firebase doesn’t have built in Fuzzy search so there is either the solution to search for exact word match, or try to figure out how the Algolia Firebase extension works (to allow full-text search on your collections).

What you’ll have to do in fact is to use the “runQuery” endpoint.
Read up on the official documentation here:
https://firebase.google.com/docs/firestore/reference/rest/v1/projects.databases.documents/runQuery

So for your use case it would be something like:

Endpoint url:

https://firestore.googleapis.com/v1/projects/{projectId}/databases/{databaseId}/documents:runQuery

And the request body should be:

{
"structuredQuery": {
    "where" : {
        "fieldFilter" : { 
        "field": {"fieldPath": "name"}, 
        "op":"EQUAL", 
        "value": {"stringValue": "theSearchTerm"}
        }
    },
    "from": [{"collectionId": "CodelessFixpersonal..."}]
    }
}

More on the available query options here (You can filter, order, etc with the different objects from this documentation):
https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery

This should retrieve the documents from the collection which match the name. But again, it will only find exact matches. So that is something to consider when building a search functionality. To avoid users not being able to find what they’re looking for I would suggest for example save the “names” that they give to local storage so that you could offer an autocomplete here on this field with an AG formula as described by above answers:

SELECT(locallyStoredListOfNames, CONTAINS(LOWERCASE(item), LOWERCASE(searchTerm)))

This would be the autocomplete list and then the user can select a value from that list. Which you can send to the query to match the field name in Firebase. This way you don’t have to worry if they remember well what name did they give to their item.

Note, In the “where” field of the query above you can offer multiple filters combined as well, so you could go crazy with creating the search terms.

Hope this helps and keep up your good work with those tutorials.

Thank you all for the help. I recently got stuck on Gappsy as a potential Appgvyer alternative so i have been spending less time here recently. Im starting to get nervous that at some point Appgyver (SAP) Will begin to see more and more value in enterprise work and phase out the community edition. I think the phasing out of the web hosting, thiugh understandable, is a potential indicator of this, regardless of how far out it may be.