Firestore database updateData()

Hi @Scott_Harrison ,
I have purchased Firestore Plugin. I can run sample code you uploaded to gitHub.
But i want to add data with hierarchical Lua table (table inside table).
For example :
firestore.updateData("cities", "LA", {values={ {1,2,3},{4,5,6} } },listener )

When i run this line, it gives runtime error.
I have tried below method as well :

local dataTbl = {}
dataTbl["values] = {}
dataTbl["values][1] = {1,2,3}
dataTbl["values][2] = {4,5,6}
firestore.updateData("cities", "LA", dataTbl, listener )

Can you please help me How can we use this data structure update in Firestore ?

Thank you.
Bhavin :slight_smile:


I don’t think 2d arrays are a thing in Firestore, you may try something like

firestore.updateData("cities", "LA", {values=json.encode({ {1,2,3},{4,5,6} }) }, listener )

I am not sure but i can show you one example which is created from another app created with native iOS (swift) ,(See Screenshot ) i want to create same data structure on firestore with solar2D App. All data structure need to updated dynamically not manually.
Like every time user do a session → i need to create new Session data document with all the information. and it requires 2d arrays.
I will try json.encode with values table same as you suggested.


– I read this and looks like it’s the same concept used in native code.

How can we create a object(map) in lua and add an array (lua table) to it and pass to firestore ?
I see in screenshot that → values is array , 0 is Map and inside 0 all fields are numbers.

I just pushed out an update for better array support on iOS( and Mac),
firestore.updateData("cities", "LA", {values={"test", "test1", "test2"} }, listener )
should work now

Hi @Scott_Harrison ,
Thanks for the improvements but still i would like to use more levels in table.
like this:

firestore.updateData("cities", "LA", {values={ {"test", "test1", "test2"},{1,2,3},{4,5,6} } }, listener )

I have to use this same structure in firestore because other application from Native updating in same database (multiple application using same database on firestore, few applications are native , one application is created using solar2d native)

Can you please help me with this structure ?

Thank you.
Bhavin :slight_smile:

I don’t believe it’s possible to recreate that structure since nested array are not supported on Firestore. This is not plugin limitation but a firestore limit. You will have to work around by break up the array into a table of random key or just encode it as json

Source: flutter - How to add nested array into Firebase Firestore? - Stack Overflow

I just saw you linked to the same post, you will have to create your own mapping solution based on your needs

That’s true, i already read that post but i don’t know how i can create my own mapping solution ?
I mean how we can do with Solar2D table with your plugin ?
I am sure that there is some trick to create this nested array on firestore dynamically.

The plugin just converts your lua arrays and table to native counterpart and uploads them to firestore. You need to figure out how to convert your nested arrays lua to table.

Edit: as the stackoverflow pointed out there is no magic solution devs are essentially left to figure it out

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.