如何使用firestore were field方法并将文档添加到另一个集合中
我正在进行一个使用商店的项目。我的结构数据:
我的代码段
//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,那么我该如何弄清楚呢?
I am working a project to use shops. My structure data:
My code snippet
//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
I want to add data to use currentuser uid and if it is matching "Blah" inside documents then add that targeting document other collection.
.adddocumets
or .setData
it isn't allowed to firestore, so how can i figure it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一口气无法向Firestore发送查询和更新语句。取而代之的是:
此外,由于
用户
是一个数组字段,因此您需要使用array-contains
操作员匹配正确的文档。There is no way to send a query and an update statement to Firestore in one go. You will instead have to:
In addition, since
users
is an array field, you'll want to use thearray-contains
operator to match the correct documents.