【问题标题】:How to create custom index for firestore query如何为 Firestore 查询创建自定义索引
【发布时间】:2019-03-27 18:14:15
【问题描述】:

我需要能够从满足某些条件的云 Firestore 数据库中检索一些数据,然后对这些数据进行排序,但我无法让我的查询正常工作。我已经读过,如果您只是运行查询,那么您的日志应该为您提供一个链接以自动创建自定义索引,但不幸的是在我的颤动日志或 android studio logcat 中我没有得到任何链接。我知道您可以在 firebase 控制台中手动创建自定义索引,所以我很乐意这样做,但我不知道如何为此创建索引。

firestore.collection('users').where('organisation_id', isEqualTo: _authenticatedUser.organisationId)
.orderBy('first_name').getDocuments()

我只需要知道如何为此查询创建复合索引,以便它可以在我的应用程序中工作

【问题讨论】:

  • 所以您是说查询失败,但您没有针对该失败的错误消息?您是否尝试过自己捕获错误?
  • @DougStevenson 成功了,我真傻,没想到这么早!谢谢
  • 您想用您的错误处理代码回答您自己的问题,以便其他有相同问题的人知道该尝试什么吗?

标签: firebase flutter google-cloud-firestore


【解决方案1】:

感谢 Dougs 的回答,我能够通过使用 try catch 包围 firestore 查询并打印出生成直接链接的平台异常来在控制台日志中获取链接

try {
        snapshot = await firestore.collection('users').where(
            'organisation_id', isEqualTo: _authenticatedUser.organisationId)
            .orderBy('first_name').getDocuments();

      } catch(e){
        print(e);
      }

【讨论】:

  • 我没有得到链接。我试图捕捉到错误。
猜你喜欢
  • 2020-01-22
  • 1970-01-01
  • 2023-02-13
  • 1970-01-01
  • 1970-01-01
  • 2014-09-06
  • 2014-03-10
  • 1970-01-01
  • 2015-03-21
相关资源
最近更新 更多