我们如何在Firestore中的数组中创建数组? [英] How can we create an array in array in Firestore?

查看:43
本文介绍了我们如何在Firestore中的数组中创建数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要像创建数组一样添加数组,您可以在图像中看到我需要在成员中添加2个数组.我需要保存uid + name.但是没有数组的选项,只能是字符串,数字,布尔值等.

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.

推荐答案

我们如何在Firestore中的数组中创建数组?

How can we create an array in array in Firestore?

您不能.您无法在另一个数组中添加一个数组.数组不是受支持的数据类型数组值.您可以添加一个数组,其中可以包含字符串,数字,布尔值,地图,时间戳,地理位置,引用,甚至可以是null但的数组.您正在寻找的是2D数组,目前不支持该数组.您无法创建数组数组.您唯一可行的选择是使用对象(地图).这样的文档应如下所示:

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.

这篇关于我们如何在Firestore中的数组中创建数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆