【发布时间】:2025-11-25 05:05:01
【问题描述】:
当我在应用索引后在 Firestore 中添加数据时(通过单击 Android Studio 终端中的链接自动生成索引)。我的数据以我想要的方式添加和查询,直到我的文档 lrNo(我在 Firestore 中的文档中的一个字段)达到 999。之后数据开始从开头添加,这破坏了我的降序。在我的情况下,我的 lrNo 和文档 ID 都是相同的。我得到的结果与我不想要的图像中显示的文档 ID 的顺序相同;我希望它按降序排列。
我已经通过点击下面的链接生成了索引。
Error: FirebaseError: The query requires an index. You can create it here:
https://console.firebase.google.com/v1/r/project/[PROJECT-NAME]/firestore/indexes?create_compo
site=[INDEX EXAMPLE] (failed-precondition)
at Object.throw_ [as throw] (http://localhost:49397/dart_sdk.js:4776:11)
at handleThenable
(http://localhost:49397/packages/firebase/src/storage.dart.lib.js:3237:21)
at handleThenable.throw (<anonymous>)
at onError (http://localhost:49397/dart_sdk.js:35663:38)
at _RootZone.runBinary (http://localhost:49397/dart_sdk.js:35547:58)
at _FutureListener.thenAwait.handleError (http://localhost:49397/dart_sdk.js:30969:50)
at handleError (http://localhost:49397/dart_sdk.js:31482:51)
at Function._propagateToListeners (http://localhost:49397/dart_sdk.js:31505:17)
at _Future.new.[_completeError] (http://localhost:49397/dart_sdk.js:31366:23)
at async._AsyncCallbackEntry.new.callback
(http://localhost:49397/dart_sdk.js:31401:31)
at Object._microtaskLoop (http://localhost:49397/dart_sdk.js:35759:13)
at _startMicrotaskLoop (http://localhost:49397/dart_sdk.js:35765:13)
at http://localhost:49397/dart_sdk.js:31707:9
下面是排序和获取数据的代码:
var temp = await fireStore
.collection("Admin")
.where("phoneNo", isEqualTo: TextFieldData.phoneNo)
.orderBy("lrNo", descending: false)
.getDocuments()
.then((value) => value);
【问题讨论】:
标签: firebase flutter dart google-cloud-platform google-cloud-firestore