[英]Swift & Firebase - Cloud firestore scalable?
I'm really new on Cloud Firestore, so it's a bit strange for me to structure the database. 我真的是Cloud Firestore的新手,所以对数据库的结构结构有点奇怪。
I would like to save my workouts. 我想保存我的锻炼。 If I were on RealtimeDatabase I would do something like that:
如果我在RealtimeDatabase上,我会做类似的事情:
WorkoutResults | +--AutoID | | | +--date | +--userID | +--result
AND 和
UserWorkoutResult | +--UserID | | | +--WodResultGeneratedID |
In that way, I can only fetch one node to a specific user. 这样,我只能将一个节点提取给特定用户。 But if I understand well on Cloud Firestore, it's not possible to query on subcollections.
但是,如果我对Cloud Firestore的理解很好,就不可能查询子集合。
So my question is, do you think this structure is good enough to scale? 所以我的问题是,您认为这种结构足以扩展吗?
WorkoutResults | +--AutoID | | | +--date | +--userID | +--result
By doing something like: 通过执行以下操作:
.whereField("userID", isEqualTo: "userIDString").whereField("date", isEqualTo: theDateIWant) ?
Your query looks fine to me. 您的查询对我来说很好。 And as Firestore promises, its performance is only related to the number of matching
WorkoutResults
, not to the size of that collection. 正如Firestore所承诺的那样,其性能仅与匹配的
WorkoutResults
的数量有关,而与该集合的大小WorkoutResults
。
But you could get the exact same result by querying collection("Users").doc("userIDString").collection("WorkoutResults").whereField("date", isEqualTo: theDateIWant)
in your first data structure. 但是,通过在第一个数据结构中查询
collection("Users").doc("userIDString").collection("WorkoutResults").whereField("date", isEqualTo: theDateIWant)
, collection("Users").doc("userIDString").collection("WorkoutResults").whereField("date", isEqualTo: theDateIWant)
结果。 The only thing that isn't possible there is to query across the WorkoutResults
for multiple users, since querying across multiple collections isn't possible. 唯一不可能的事情是跨多个用户查询
WorkoutResults
,因为不可能跨多个集合进行查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.