![](/img/trans.png)
[英]How to check if a user already exists in a Firestore collection after signing in with Firebase Auth in SwiftUI
[英]How to check if value exists in other collection in Firebase/Firestore
我有两个 collections:项目和冲刺。 在项目内部,我有一个带有对象的成员数组。 并使用 Firebase 安全规则,我想检查这些对象之一中是否存在值。
工程实例
冲刺示例
我想要做的是,当用户更新或创建 sprint 时,我想检查登录用户(request.auth.uid)
是否与项目成员数组中的其中一个 userId 匹配。 但我只是不知道如何实现这一点。
这就是我目前拥有的,显然不起作用。
match /sprints/{document} {
allow read: if request.auth.uid != null
allow update, create: if get(/databases/$(database)/documents/projects/$(resource.data.project)).data.members == request.auth.uid
}
有人可能知道该怎么做吗?
提前致谢
您将无法使用此数据结构执行此操作:您需要遍历成员,而您不能在规则中执行此操作。
但是可行的是使用 map 而不是以 uid 作为键的数组。
{
archived: false
id: "asdasd"
members: {
firstuid: { name: "Bob", role: "Prog"}
seconduid: { name: "Alice", role": "PM"}
}
}
然后以下规则将完成这项工作:
match /sprints/{document} {
allow read: if request.auth.uid != null
allow update, create: if get(/databases/$(database)/documents/projects/$(resource.data.project)).data.members.get(request.auth.uid, null) != null
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.