如果我知道其标题字段值而不是ID,是否可以向现有文档添加新字段?

我创建城市文档,并在其中保存一些字段,例如标题和说明。以后是否可以通过知道该db.collection路径的城市名称而不是ID来向特定城市添加一些字段?

添加了第一个元素

public createSavedCity(title: string,desc: string): void {

const cityFields = {
  title: title,description: desc
}



this.db.collection('saved').add(savedFields);}

我将使用新功能来更新文档,该文档将接收要更新的文档标题作为参数

updateDoc(savedTitle: string,newItem: string) : void {

  this.db.collection.(`saved/${savedTitle}`).update({newField: newItem});

}
WANGpingping456 回答:如果我知道其标题字段值而不是ID,是否可以向现有文档添加新字段?

是的,您可以query使用该标题的文档,迭代结果,然后使用update()方法通过DocumentReference更改现有文档的内容。

本文链接:https://www.f2er.com/3150915.html

大家都在问