Firestore and List of Objects

Hi all… I have been looking at this all day now… need heeeeelp :weary:

Not sure where I do things wrong, but here it goes…

In my app I have an App Variable as a list of objects with id, Counter, Language

In my Firestore DB I want to store these values under each user. In my user collection there is a document for each user. Where I currently have a field called EroLangArray.

image

I am not totally sure this is the right way to store a list of objects in Firestore?!? But using the ‘map’ type in a new field, I managed to be able to create the field Counter, LangID and Language (Counter and LangID are numbers and Language is Text - same in the previous mentioned app variable)

I have a Data Resource called “Users”, that connects to the Users Collection in Firestore. This works just fine, and I can get all the user data.

Some hours ago, I had an API configuration for the data schema, where I had “EroLangArray” as a list of objects. Counter, LangId and Language was set with their respective data formats. This worked fine for getting data. I could use to repeat a List item, and I could access the data just fine.

When I wanted to update the records with new values, I simply just cant write the new data back. Every time I get an error: "ReferenceError : Can’t find variable: Buffer"
(I use the Update Record" Flow function to do this.)

For fun / testing / debugging, I tried to create a new record instead, using the Create Record Flow function. Same result… "ReferenceError : Can’t find variable: Buffer"

If I remove the configuration of the EroLangArray, and try to update records and create new records, everything works fine. So it is fair to assume, that the issue is with my array of objects?

When there is a reference to EroLangArray in the Schema, no updates or creates work. (I can still read data - and use it for repeats and use data on labels etc…)
Even if I create a new record with just a Name and no data in the EroLangArray, it still fails…

image
image

I tried to connect to the data via the REST API… Just to see the auto generated schema. And it looks like this:

image

So I have manually recreated this schema now, in my “Users” Firestore connection.

It is a bit long… Here is a part of it:

And currently my Update / Create Record looks like this for the EroLangArray
image

Custom list looks like this:

Questions:

  1. Am I storing lists of objects correctly in Firestore? There aren’t the many options…
    image

  2. Should the update / create functions work just fine with my first basic schema?

  3. Is it really necessary to create this crazy long and complicated scheme?

  4. What is the easiest way to write a list of objects to the database?

Any other input, suggestions and naturally solutions will be much appreciated!

Thanks for take the time - Michael

1 Like

Hi, here’s a working example! items is an array, and the items are of type map.

In Composer, the schema for Products is:

type: text
items: list of objects with properties manufacturer: text and price: number

I created a “Collection of records” type data variable from the Firestore resource called Products, and I’m using the ENCODE_JSON() formula here to show it as a string in a paragraph component:

image

Hope this helps you get forward!

1 Like

Hi Mari,
thanks for the explanation and the screenshot from firestore.

Still the part about retrieving the data into AppGyver is to fast for me :wink:

  • when you say “I created a list type data variable called …”

a) composer allows me to create e.g. a data varialbe ‘Collection of data records’, but this is not a list


b) composer also allows me to create a page variable with value type ‘list’ , but this is not a data variable.

I am confused about how to bring these two parts together :hushed:

1 Like

Hi, sorry I meant the “Collection of records” type :slight_smile:

2 Likes

Hey @Mari - Thank you so much! Will give it a try asap :slight_smile:

Michael

1 Like

Hello again @Mari

I have tried to walk through your explanation - but I have to admit that I simply don’t get it… Sorry. I am trying hard here to understand what your thoughts were… any chance you can fill in some more screenshots?

Another thing is, that this seems to retrieve the data, which I already managed to do… My real issue is when I try to write / update the records.
Any thoughts on that?

Michael

1 Like

Hi, that’s ok! If you are unfamiliar with using data in Composer, I’d start from watching these videos.

Here’s how I would create a new record with the example setup:

Here I’m just binding it to a static value {type: "mouse", items: [{manufacturer: "Dell", price: 30}]}

When I click the “Create record” button in the web preview and refresh the page, “Products” has updated to include the mouse type:

Similarly, I can update the records using the “Update record” flow:

I have put in the ID of the record I just created as identifier, and set the record to {type: "mouse", items: [{manufacturer: "Dell", price: 50}]}

Again, the data changes accordingly:

This example is a bit dumb in the way that it uses static value bindings, but you can make use of variable bindings in your app to get the data from for example user input in a form. :slight_smile:

Hi @Mari,

Thank you for elaborating. However, it still does not work for me…

Not sure what you mean by:

it looks like you bind the value through the binding editor…(I can’t see a way to use a static value here)

This is mine:

this is my list of values:

When I push the button, I get this error (same as in my initial post):

As you can see above / behind my error message I do get the data with the ENCODE_JSON-way.

What am I doing wrong here… I am going crazy :wink:

Michael

How are you connecting to Firebase? Are you using the connector as instructed in this video?

Hi, I watched the videos and even the “working with objects” video but I can’t find were can I set this items: list of objects with properties in the schema, can you please tell me were I can set this?
Thank you

HI @Maxwell_Swamy , first, create the items property, then set its type to “List” and then the “List item type” to “Object” – then you can add the object properties.

1 Like

Thank you it worked,
Is there a way to get this data as a list of separated rows for every item inside there? to show it clear to the app user?

Thanks in advance.

Is there any way to sort the data variables in descending order?

Hi @Mari. I recreated your example. But can’t get it to work. I can update the “type” field just fine, but can’t do it with array of maps. Would you please take a look at my screenshots?





I also tried building the object manually but had no success.

Hi Mari,

I have had a look at this and in web preview my firebase create record works but as soon as I do it in the app preview it doesn’t work on my iphone. Is there a dependance that I am missing because teh error I get is “ReferenceError:Cant find Variable: Buffer”