相关疑难解决方法(0)

如何自动为Cloud Firestore创建索引?

我有一个集合,Lists其中存储了一堆文档.每个文档都包含一些细节和一个集合users.我users使用uid作为键并将boolean作为值存储在Collection中的用户.这意味着只有那些用户才能阅读该特定列表.这是我的数据库结构.

在此输入图像描述 在我的代码中,我使用此查询:

FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference listsRef = rootRef.collection("Lists");
Query query = listsRef.orderBy("date").whereEqualTo("users."+uid, true);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

FAILED_PRECONDITION: The query requires an index. You can create it here: ...
Run Code Online (Sandbox Code Playgroud)

如果我去控制台创建所需的索引,一切正常.但是是否有可能自动创建索引,因为我无法为加入我的应用程序的每个用户手动创建索引.如果我为每个用户提供了一些排序索引,是否会出现问题?

还有另一种解决方法吗?

提前致谢!

android firebase google-cloud-firestore

5
推荐指数
1
解决办法
2170
查看次数

标签 统计

android ×1

firebase ×1

google-cloud-firestore ×1