繁体   English   中英

如何使用 firestore wherefield 方法并将该集合的文档添加到另一个集合

[英]how to use firestore wherefield method and adding document that collection to another collection

我正在做一个使用商店的项目。 我的结构数据:

在此处输入图像描述

我的代码片段

//current user sign in here and uid "VjZfKF1zmrV00C9VeTZxRmogybA2"
let currentUser = Auth.auth().currentUser
let db = Firestore.firestore()
db.collection("Blah").whereField("users", isEqualTo: currentUser?.uid).collection("otherPath").document().addDocument

我想添加数据以使用 currentuser uid,如果它在文档中匹配“Blah”,则将该目标文档添加到其他集合。

.adddocumets.setData不允许 firestore,所以我怎么知道呢?

无法在一个 go 中向 Firestore 发送查询和更新语句。您必须:

  1. 执行查询以确定需要更新的所有文档。
  2. 在您的应用程序代码中循环该查询的结果。
  3. 在该循环内依次更新每个文档。

此外,由于users是一个数组字段,您需要使用array-contains运算符来匹配正确的文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM