Firestore Query filter document Id

Hi, i have a question about using filters with firebase default configuration.

After connect to Firestore I can get all collection, but when I use the feature of firebase to make this filters calls I get an error if i try to search by id.

Appgyver understand id as propriety instead document id

In appgyver the id is the documentId, but How access document id in filter and order ?

The firebase-ID of a firebase-document is the last part of the “name” property. To isolate (and then filter) for this ID, you can use the functions

  • LOOKUP() → “name” of the document
  • SPLIT() at all “/”
  • LAST_ITEM()

The functions are explained in the AppGyver docs.

I wish to filter using the firestore search, instead in Appgyver.

I Guess if we set the sort in query and let the firebase solve and answer the sorted result as requested.

If possible, off course.

When we search with id, instead firestore read as id of document, It understand as a document attribute.

You have to use Indexing in Firebase to use filter queries. In my app I set this in the Rules of my database (i use RealTime Database but should be same or similar for Firestore)

Capture

Then you can do queries, like "orderBy=“something”&equalTo=“something”. In my app I query by “Name”:

"https://gud-boi-multimedia-default-rtdb.firebaseio.com/PrayPals/DATA/USERS.json" + "?orderBy=\"Name\"&equalTo=" + "\"" + CAPITALIZE(LOWERCASE(pageVars.PAGE_PalName)) + "\""

Hope this helps. You can find info on this in the Firebase docs.

1 Like

When trying this filter query with firestore I get a result, that I do not understand:

…?orderBy=ownedByDepartementID
→ works like expected by delivering the documents in a ordered way.

?orderBy=ownedByDepartementID&equalTo=ywBOzWNtKw4YVePba1Pf
→ does not work and returns an error (see below); comparing to Retrieving Data  |  Firebase I am not seeing what I do wrong :dizzy_face: ; Do you understand the reason? Is there a difference between firestore and the real time database in this topic?

{
“error”: {
“code”: 400,
“message”: “Invalid JSON payload received. Unknown name “equalTo”: Cannot bind query parameter. Field ‘equalTo’ could not be found in request message.”,
“status”: “INVALID_ARGUMENT”,
“details”: [
{
@type”: “type.googleapis.com/google.rpc.BadRequest”,
“fieldViolations”: [
{
“description”: “Invalid JSON payload received. Unknown name “equalTo”: Cannot bind query parameter. Field ‘equalTo’ could not be found in request message.”
}
]
}
]
}
}

Hi there from what you say, i get that in this way you can get the id of a document from its name,
But is there any way to get a list of the document ids of a whole collection?

I hope you can give me some help
thank you in advance.

The only way I can think of is to

  1. GET the entire collection with all documents (with flow function http request),
  2. retrieve the IDs from each document

Alright but how can i achieve the second part of retrieving the ids from each document and putting them in a list?

Of course the string for a collection is longer than for a single document. But the approach stays the same.

As a string the collection looks e.g. lilke below. Starting from this you could use the formula functions to drill down to the "name"s. As the first try I would reduce the collection to the list containing the documents and then use the “SELECT” (SELECT - Composer) together with the other functions mentioned in the tread earlier. As I did not need it for my app there is nothing I can copy and paste here. I am afraid you need to experiment a bit…

{
“documents”: [
{
“name”: “projects/YOURPROJECT/databases/(default)/documents/GINYcj2hvTf8jDORVln2eBkzJDh1/contentOwnedByUser/organizations/4nm5zW4BL7gZtA3E6Tu9”,
“fields”: {
“orgName”: {
“stringValue”: “Alpha Inc.”
}
},
“createTime”: “2021-09-07T12:51:57.487028Z”,
“updateTime”: “2021-09-07T12:51:57.487028Z”
},
{
“name”: “projects/YOURPROJECT/databases/(default)/documents/GINYcj2hvTf8jDORVln2eBkzJDh1/contentOwnedByUser/organizations/86jcHaoaoDfYRAitzxff”,
“fields”: {
“orgName”: {
“stringValue”: “Big Coorp”
}
},
“createTime”: “2021-09-03T11:43:54.204508Z”,
“updateTime”: “2021-09-03T11:43:54.204508Z”
},
{
“name”: “projects/YOURPROJECT/databases/(default)/documents/GINYcj2hvTf8jDORVln2eBkzJDh1/contentOwnedByUser/organizations/u8HT689jc5XrNSvJrxd6”,
“fields”: {
“orgName”: {
“stringValue”: “Beta Inc.”
}
},
“createTime”: “2021-09-08T08:26:32.204516Z”,
“updateTime”: “2021-09-08T08:26:32.204516Z”
}
]
}

Yeah i get it and i will look into it more,
Thank you so much !!