我正在使用具有以下结构的 firebase cloud firestore datadabse 构建应用程序:
我正在查询用户的书籍,其中字段“StartDate”大于 0 且“EndDate”等于 0,然后该查询应按标题排序。
CollectionReference booksCollection = mFirebaseDatabase.collection("users").document(user.getUid()).collection("books");
Query databaseQuery = booksCollection.whereGreaterThan("StartDate", 0).whereEqualTo("EndDate", 0).orderBy("Title");
databaseQuery.get()
Run Code Online (Sandbox Code Playgroud)
为此,我读到您需要使用索引(尽管我没有在错误消息中获得索引的链接,因为它表明我应该这样做)。我的索引如下所示:
但我收到错误消息:
java.lang.IllegalArgumentException:查询无效。您在字段 'StartDate' 上有一个不等式过滤器(whereLessThan()、whereGreaterThan() 等),因此您还必须将 'StartDate' 作为您的第一个 orderBy() 字段,但您的第一个 orderBy() 目前在该字段上'标题' 代替。