【发布时间】:2020-11-04 14:56:23
【问题描述】:
我正在尝试通过字段值检索单个文档,然后更新其中的字段。
当我执行.where("uberId", "==",'1234567') 时,我将获得与1234567 匹配的字段uberId 的所有文档。
我确信只有一份这样的文件。但是,我不想使用 uberId 作为文档的 ID,否则我可以轻松地通过 ID 搜索文档。还有其他方法可以通过字段 ID 搜索单个文档吗?
到目前为止,阅读文档,我可以看到:
const collectionRef = this.db.collection("bars");
const multipleDocumentsSnapshot = await collectionRef.where("uberId", "==",'1234567').get();
那么我想我可以通过const documentSnapshot = documentsSnapshot.docs[0] 获取唯一现有的文档参考。
但是我想用这个来更新文档:
documentSnapshot.set({
happy: true
}, { merge: true })
我收到一个错误Property 'set' does not exist on type 'QueryDocumentSnapshot<DocumentData>'
【问题讨论】:
标签: javascript firebase google-cloud-firestore