【问题标题】:Cloud Firestore Nested arrays are not supported Error Flutter不支持 Cloud Firestore 嵌套数组 Error Flutter
【发布时间】:2021-03-10 16:27:01
【问题描述】:

我正在尝试将 json 导入到包含嵌套数组的云 Firestore 集合中,但即使 FieldValue.arrayUnion 函数出现错误“无效数据。不支持嵌套数组”。

 FirebaseFirestore.instance
              .collection('universities2')
              .doc(value.docs.first.id)
              .update({
            'departments': FieldValue.arrayUnion([
              json["Sayfa1"][0][x]["department"][0]["name"],
              json["Sayfa1"][0][x]["department"][0]["fields"]
            ])
          });

有什么方法可以实现吗?

【问题讨论】:

    标签: firebase flutter google-cloud-firestore


    【解决方案1】:

    node.js 中使用扩展运算符(...).apply(this, array) 正在工作,例如:

     FirebaseFirestore.instance
                  .collection('universities2')
                  .doc(value.docs.first.id)
                  .update({
                'departments': FieldValue.arrayUnion(...[
                  json["Sayfa1"][0][x]["department"][0]["name"],
                  json["Sayfa1"][0][x]["department"][0]["fields"]
                ])
              });
    

     FirebaseFirestore.instance
                  .collection('universities2')
                  .doc(value.docs.first.id)
                  .update({
                'departments': FieldValue.arrayUnion.apply(this, [
                  json["Sayfa1"][0][x]["department"][0]["name"],
                  json["Sayfa1"][0][x]["department"][0]["fields"]
                ])
              });
    

    【讨论】:

    • 让我知道这个答案是否也适用于 Flutter。
    猜你喜欢
    • 1970-01-01
    • 2023-01-03
    • 2020-02-29
    • 1970-01-01
    • 2021-09-30
    • 2021-06-17
    • 2018-11-26
    • 2021-01-05
    • 1970-01-01
    相关资源
    最近更新 更多