【发布时间】:2019-10-28 16:08:28
【问题描述】:
我得到了以下 Firebase 文档:
{
"customField1": "customValue1",
"customField2": "customValue2",
"fieldToChange: "valueToChange"
}
我想知道怎么做两个操作:
找到将“customField1”设置为“customValue1”的文档并将“valueToChange”更新为其他内容。
找到“customField1”设置为“customValue1”且“customField2”设置为“customValue2”的文档,并将“valueToChange”更新为其他内容。
我怎样才能做到这一点?
我只看到需要 docId 的选项:
const uploadCollection = this.db.collection<any>('uploads');
return await uploadCollection.doc(docId).update({ 'fieldToChange': 'another value' });
【问题讨论】:
-
Firestore 中没有更新查询的概念。要更新文档,您需要知道该文档的完整路径。因此,如果您想更新与某个条件匹配的文档,您需要针对该条件执行查询,遍历所有生成的文档,并更新每个文档。见stackoverflow.com/questions/54541228/…
标签: javascript firebase google-cloud-firestore