Firebase Firestore 复合索引限制为 200 - 如果在具有大量用户的嵌套结构中使用,是否达到限制?
Firebase Firestore composite index limit of 200 - is it reached if used in nested structure with lots of users?
我对 Firestore 将什么计入其 200 的复合索引限制感到困惑。
比如我有几千个用户,每个用户都有几千个字符。我希望每个用户都能够根据这些角色的不同参数对他的角色进行排序。我有以下结构,其中 {} 表示通配符:
users:
{user_ID}
user_name: {user_name}
user_email: {user_email}
characters:
{characterUID}
name: {name}
strength: {strength}
speed: {speed}
stamina: {stamina}
date_created: {timestamp}
所以,在 android 中,我会这样做:
Query query = fsDB.collection("users").document("user_ID").collection("characters")
.orderBy("strength").orderBy("name");
或者这样:
Query query = fsDB.collection("users").document("user_ID").collection("characters")
.orderBy("speed").orderBy("date_created");
然后,我将在 Firebase 控制台中创建复合索引:
Collection Group: characters
Fields Indexed: strength , name
和
Collection Group: characters
Fields Indexed: speed, date_created.
那么,根据 Firebase,这只是 2 个复合索引吗?还是乘以我拥有的用户数?
如果乘以用户数,我应该如何重组我的数据才不会运行陷入这个问题?
谢谢-
杰夫
在 Firebase 与 Sam Stern 讨论后,
答案是索引没有乘以用户数
来自山姆----
Indexes actually on depend on the collection name so all of the "characters" subcollections of your "users" documents can share the same indexes.
You'd only approach the 200 index limit if you had 200+ different field combinations you wanted to index. Hope that makes sense!
- Sam
我对 Firestore 将什么计入其 200 的复合索引限制感到困惑。
比如我有几千个用户,每个用户都有几千个字符。我希望每个用户都能够根据这些角色的不同参数对他的角色进行排序。我有以下结构,其中 {} 表示通配符:
users:
{user_ID}
user_name: {user_name}
user_email: {user_email}
characters:
{characterUID}
name: {name}
strength: {strength}
speed: {speed}
stamina: {stamina}
date_created: {timestamp}
所以,在 android 中,我会这样做:
Query query = fsDB.collection("users").document("user_ID").collection("characters")
.orderBy("strength").orderBy("name");
或者这样:
Query query = fsDB.collection("users").document("user_ID").collection("characters")
.orderBy("speed").orderBy("date_created");
然后,我将在 Firebase 控制台中创建复合索引:
Collection Group: characters
Fields Indexed: strength , name
和
Collection Group: characters
Fields Indexed: speed, date_created.
那么,根据 Firebase,这只是 2 个复合索引吗?还是乘以我拥有的用户数?
如果乘以用户数,我应该如何重组我的数据才不会运行陷入这个问题?
谢谢-
杰夫
在 Firebase 与 Sam Stern 讨论后,
答案是索引没有乘以用户数
来自山姆----
Indexes actually on depend on the collection name so all of the "characters" subcollections of your "users" documents can share the same indexes.
You'd only approach the 200 index limit if you had 200+ different field combinations you wanted to index. Hope that makes sense!
- Sam