How can we create an array in array in Firestore?

爱⌒轻易说出口 提交于 2021-02-05 09:18:50

问题


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.


回答1:


How can we create an array in 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 allowed. 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.



来源:https://stackoverflow.com/questions/59067832/how-can-we-create-an-array-in-array-in-firestore

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!