4

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

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@Umaiz Khan, As Alex mentioned it is not possible to do that, but even if you could have create an array inside another one, your ability to interact with the inner array would be pretty much limited. you can consider creating a subcollection instead of your outer data structure (array)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.