Server-side (Cloud Firestore) query returning 20 of 20000 documents

Hi I am struggling - I am an automotive manufacturing engineer, not a REST developer.

I need to build a containment process that scans an end-item number and then presents a list of all the component parts. The app would scan the barcode of each component part and confirm it is correct. The returned documents for each component part would include multiple fields (part number, description, model).

My collection is in Cloud Firestore now (rules are open for the next 15 days):
https://firestore.googleapis.com/v1/projects/paccar-build-verification/databases/(default)/documents/PACCAR Filtered BOM
I tried to follow:
Google Firestore REST API integration - AppGyver
but I am getting lost.

If the server-side query can be executed in AppGyver then I will not change the schema of my database, but if that’s like fitting a round peg into a square hole then maybe I can change my db schema to allow using a get call (each end-item part number would be unique in the db) to search for only one field, returning an object/document of component parts).

Any comments would be appreciated.

Hi, I am not sure what exactly the core of your question is.

Just two thougts that I like to share with you:

  • you can increase the number of returned documents by adaption the ‘pagination’. The default for firestore is 20 documents and you can increase that number like this:

  • I would not recomend to download the 20.000 documents each time the app is used. Instead the barcode should give the ID for the particular document, that relates to the automotive part and download only that single document.

I guess I was not clear enough - let me add some detail. The database does contain about 20000 documents, and is maintained elsewhere. I am trying to use the CREATE RECORD (POST) to submit a query. The value of the barcode exists on a small subset of the database documents. The query is expected to return approximately 20 documents (variable) all with the same customer barcode. The returned documents contain 5 other fields of importance.

POST https://firestore.googleapis.com/v1/{parent=projects//databases//documents}:runQuery and my trouble is in building the requestBody.

Ok, now I understand what you want to do. I am not experienced in how to write a query, therefore my general recommendation is:

1 Like

I use Firefoo to help me with all things firebase related.

It allows you to build queries in a simple manner then shows the final format. It also helps by creating any necessary indexes in Firebase.

2 Likes

Phil_Evans thank you for the hint. That worked for me. Once I got the query working in Firefoo, I also got it working in AppGyver as a data resource. I can paste the structuredQuery as a formula (but it never saves) and the test runs Status:OK and the results are what I expect. Now I’m trying to get the documents into a component; I’m not stuck yet, but it’s not straight forward.

The results are multiple documents each with five fields, copied below. When I try to create a schema, I cannot seem to get more than one field - the fields object is a collection of key:values, where the keys should be the field type, but AppGyver wants the keys to be unique.
{
“document”: {
“name”: “projects/{db}/databases/(default)/documents/{collection}/014P990n219646”,
“fields”: {
“MATNR_MODULE”: {
“stringValue”: “8NA3011341”
},
“MATNR_COMPONENT”: {
“stringValue”: “R8648002”
},
“COMPONENT_DESC”: {
“stringValue”: “SHROUD- FAN”
},
“MODULE_DESC”: {
“stringValue”: “8NA Cooling Module”
},
“MATNR_CUSTOMER”: {
“stringValue”: “F31-1058-3011341”
}
},
“createTime”: “2022-02-12T02:25:00.425742Z”,
“updateTime”: “2022-02-12T02:25:00.425742Z”
},
“readTime”: “2022-02-23T00:55:13.056517Z”
},
{
“document”: {
“name”: “projects/{db}/databases/(default)/documents/{collection}/CDcI3P79A2r28I”,
“fields”: {
“MATNR_COMPONENT”: {
“stringValue”: “X7441001”
},
“MODULE_DESC”: {
“stringValue”: “8NA Cooling Module”
},
“COMPONENT_DESC”: {
“stringValue”: “SEALING-SURROUND-ENT”
},
“MATNR_MODULE”: {
“stringValue”: “8NA3011341”
},
“MATNR_CUSTOMER”: {
“stringValue”: “F31-1058-3011341”
}
},
“createTime”: “2022-02-12T02:25:00.685566Z”,
“updateTime”: “2022-02-12T02:25:00.685566Z”
},
“readTime”: “2022-02-23T00:55:13.056517Z”
}

1 Like

As soon as your test run works fine, you can set the schema from response.

image

1 Like