Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we create an array in array in Firestore?

I need to add array in an array-like I am creating you can see in the image I need to add 2 arrays in member. I need to save uid+name. but there is no option of the array just string, number, boolean etc. enter image description here

like image 399
Umaiz Khan Avatar asked Oct 29 '25 08:10

Umaiz Khan


1 Answers

How can we create an array in an array in Firestore?

You cannot. There is no way you can add an array within another array. The array is not a supported data type when it comes to array values. You can add an array that can contain strings, numbers, booleans, maps, timestamps, geopoints, references, or even null but not arrays. What you are looking for is a 2D array, which is currently not supported. You cannot create an array of arrays. The only viable option that you have is to use objects (maps). Such a document should look like this:

autoId
  |
  --- myArray
       |
       --- 0
       |   |
       |   --- propertyOne: "value"
       |   |
       |   --- propertyTwo: "value"
       |
       --- 1
           |
           --- propertyOne: "value"
           |
           --- propertyTwo: "value"

So you'll end up having an array of Maps. To get that data back, simply get the document and iterate through that list of Maps.

like image 99
Alex Mamo Avatar answered Oct 31 '25 00:10

Alex Mamo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!