我想知道为以下用例实现的最佳方法/模式。
我使用 Firebase身份验证注册用户,并且工作正常。
执行身份验证后,我需要从 Cloud Firestore 集合中提取,例如user_profile
,与已登录用户相关的数据。
问题是该集合的id
与用户无关,因为它是由Firestore自动生成的。因此,我不知道在<user>
db.collection("user_profile").doc(<user>).get()
我提出的一个可能的解决方案是将用户id
存储在user_profile
中,然后像这样查询整个集合
db.collection("user_profile").where("id", "==", id_from_auth).get()
制作集合的id
字段索引。
这是一个好方法吗?
是否有better/smarter/automatic
方法可以做到这一点?
答案 0 :(得分:0)
通常将每用户数据存储在由Firebase身份验证进行身份验证的用户的uid键入的文档中。