【问题标题】:Updating firestore array of maps shows error : Unsupported field value: undefined更新地图的firestore数组显示错误:不支持的字段值:未定义
【发布时间】:2020-03-01 15:15:38
【问题描述】:

我在 Firestore 中有一个文件,如下所示

我想要做的是更新这个字段的时间和阶段 我用更新和设置方法尝试了这些

db.collection("record").doc("user"+user).collection("datas").doc("roadmap").update({
  first:[{
  0:[ stage:"new stage",
    time:"new time,
    done:false
  }]
  }]
  })

db.collection("startups").doc("user"+user).collection("datas").doc("roadmap").update({
  first:{[ 
     stage:"new stage",
    time:"new time",
    done:false
  }]
  })

但它总是显示错误,例如:[![FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined]

【问题讨论】:

    标签: arrays reactjs firebase google-cloud-firestore arrayobject


    【解决方案1】:

    以下应该可以解决问题:

    db.collection("record").doc("user"+user).collection("datas").doc("roadmap")
    .update({ first: [{ stage: 'new stage', time: 'new time', done: false }] });
    

    这会起作用,因为您的数组只有一个元素(地图)。

    请注意,如果您想用多个元素修改数组的一个特定元素,您需要先在前端读取数组,修改数组,然后将修改后的数组写回 Firestore。


    即使它不是您要查找的内容,也值得注意arrayUnion()arrayRemove() 方法,请参阅here 了解更多详细信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-14
      • 2020-06-13
      • 2021-07-20
      • 2017-01-10
      • 1970-01-01
      • 2021-07-11
      • 1970-01-01
      相关资源
      最近更新 更多