我正在创建一个使用 firebase Cloud Firestore 数据库的应用。结构似乎是集合/文档/字段。我正在考虑使用用户 ID 作为集合名称的前缀,或者只是一个用于 userId 的字段。
我目前正在使用:
Firestore.firestore().collection("Events").
这可以更改为带有 userId 的前缀事件
我目前正在阅读使用中的所有内容:
reference(to: "Events").addSnapshotListener{ (snapshot, _) in
guard let snapshot = snapshot else {return}
for document in snapshot.documents {
// code here
}
}
最佳答案
在集合名称上使用前缀并不是一个好主意。这不适用于安全规则。
每个用户数据的通常结构是拥有一个包含 ID 为用户 ID 的文档的集合。然后,您可以在该文档 ID 下进一步组织子集合中的其他数据。
/users
/uid1
/uid2
/events
/likes
/history
然后,您可以write security rules using the user's UID非常容易。
关于swift - 如何在 firebase 中隔离用户数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56571518/