首页 > 解决方案 > 如何使用where和update

问题描述

我正在尝试这样做:

database.collection('UsuariosDev').where('Telefono', '==', textInput.current.value)
    .update({
        citas: firebase.firestore.FieldValue.arrayUnion(database.doc('NegociosDev/Peluquerías/Negocios/PR01/citas/' + docRef.id))
})

从集合“UsuariosDev”中获取文档,其中“Telefono”等于“textInput.current.value”,然后更新它。但似乎我不能在“where”旁边使用“update”。有任何想法吗?

标签: javascriptgoogle-cloud-firestore

解决方案


Firestore 不支持更新查询。要更新文档,您需要知道其完整路径。因此,要更新与查询匹配的所有文档,您需要:

  1. 对数据库执行该查询
  2. 循环生成的文档
  3. 依次更新每个文档

另见:


推荐阅读