【问题标题】:How to create index for a query uses the document id cloud firestore如何使用文档 ID cloud firestore 为查询创建索引
【发布时间】:2018-12-02 16:21:35
【问题描述】:

我在我的 android 应用程序中使用此查询:

        fireStoreQuestions.document(subject).collection(subject)
            .whereEqualTo("reviewed", true)
            .whereGreaterThan(FieldPath.documentId(), randomId)
            .limit(1)
            .get()

我想知道如何在 Cloud Firestore 中为该查询添加索引。我不知道如何在索引中表示文档 id。

【问题讨论】:

    标签: java android firebase google-cloud-firestore


    【解决方案1】:

    您可以在您的Firebase Console 中手动创建index,或者如果您使用的是 Android Studio,您会在您的 logcat 中找到一条听起来像这样的消息:

    W/Firestore:(0.6.6-dev)[Firestore]:侦听查询(主题其中已审查 == true 和 id > randomId)失败:状态{code=FAILED_PRECONDITION,描述=查询需要索引。你可以在这里创建它:https://console.firebase.google.com/project/...

    因此,您只需单击该链接或将网址复制并粘贴到网络浏览器中,您的索引就会自动创建。

    【讨论】:

    • 我有一个类似的查询,它也使用文档 ID,并希望通过 Firebase 控制台手动构建查询。如何将文档 ID 添加到索引中。具体来说,“创建复合索引”向导要求输入“字段路径”值。
    • @cjmconie 这是一个无法在评论中简单回答的问题,所以我建议您使用自己的MCVE 发布一个新问题,以便我和其他 Firebase 开发人员可以帮助您。
    • 同意。我创建了一个新帖子 stackoverflow.com/q/63019155/3589408 - 现在已得到答复。
    猜你喜欢
    • 2020-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多